Forum Doku Wiki Blog

Forumsarchiv 2000, Januar
Datum ... schon wieder ...

archivierte Beiträge lesen

  1. (PERL) Datum ... schon wieder ... von Poldi, 11. 01. 2000, 23:23

Datum ... schon wieder ...

Der folgende Beitrag wurde am 11. 01. 2000, 23:23 Uhr von Poldi veröffentlicht.

Hallo!

Eigentlich will ich ja nur einen ganz normalen Datumsstring bekommen, so nach dem Schema:
DD:MM:YYYY HH:MM:SS aber ich scheitere schon am Anfang. Folgendes sollte doch
eigentlich funktionieren:

use Time::localtime;

$tm=localtime($TIME);
$hour=$tm->hour;

Alles was ich damit erreiche ist aber, dass $hour immer 1 ergibt. Was habe ich vergessen?

Gruesse

Poldi.

Datum ... schon wieder ...

Der folgende Beitrag wurde am 12. 01. 2000, 00:02 Uhr von Calocybe veröffentlicht.

Hi!

Warum nicht einfach das
> use Time::localtime;
weglassen, damit die eingebaute localtime-Funktion verwendet wird, und dann sowas wie das hier?

    @MONTH_NAMES = ("Januar", "Februar", "März", "April", "Mai", "Juni",
        "Juli", "August", "September", "Oktober", "November","Dezember");


    ($sec, $min, $hour, $mday, $monthindex, $year, $wday, $yday, $isdst) = localtime(time);

    $month = $monthindex + 1;
    $shortyear = $year % 100;
    $year += 1900;

    for ($sec, $min, $hour, $month, $mday, $shortyear) {
        ($_ < 10) and $_ = "0$_";
    }

    $date = "$mday.$month.$shortyear $hour:$min:$sec";
    $long_date = "$mday. $MONTH_NAMES[$monthindex] $year, $hour:$min:$sec";


Calocybe

Datum ... schon wieder ...

Der folgende Beitrag wurde am 12. 01. 2000, 08:25 Uhr von Frank S. veröffentlicht.

> Hallo!
>
> Eigentlich will ich ja nur einen ganz normalen Datumsstring bekommen, so nach dem
> Schema:
> DD:MM:YYYY HH:MM:SS aber ich scheitere schon am Anfang.

Hi Poldi,

eine andere Möglichkeit ist die hier (so Deine Scripts auf einem UNIX-Server laufen):

$getdate = "/usr/bin/date";

$actdate = `$getdate +"%D"`; # hier kannst Du alle möglichen Parameter angeben
chop($actdate);

Hier die komplette Beschreibung von date:

NAME
     date - print date and time or set system clock

SYNOPSIS
     date[ -u][ +format]                                           Format 1

     date[ -a[ -] ssss.fff][ -u][ new_date]                        Format 2

DESCRIPTION
     date writes the current date and time on standard output (Format 1).
     The form in which date outputs dates and times depends on the value of
     the environment variable LC_TIME or, if that is undefined or null, on
     the value of LANG. If both are undefined or null, or if the required
     database is not available, or if one of the NLS variables has an
     invalid value, date acts as if in a non-internationalized system,
     printing dates and times in American format.

     If you are the system administrator, you can also use date to set the
     system clock (Format 2); but you should not do this unless you are in
     single-user mode and all file systems have been unmounted. Changing

   Mode of operation

     The system operates in coordinated universal time UTC (Universal Time
     Coordinated; synonymous with Greenwich Mean Time/GMT). date takes care
     of conversions to and from UTC to local time. If the environment vari-
     able TZ is defined, it is used to determine the timezone and to con-
     vert UTC to local time [see sh(1), "Standard shell variables"].

OPTIONS
   Format 1: Print date and time

     date[ -u][ +format]

     No argument specified:
          date prints the current date and time in a format governed by the
          current locale.

     -u   Displays the current date and time in Greenwich Mean Time (GMT).

          If the -u option is set, the +format specification is ignored.    
   +format
          The format argument defines the output format for date. If format
          contains blanks or tabs or other shell metacharacters which you
          do not want the shell to interpret, you should enclose format in
          single quotes: +'format'.

          format is essentially similar in format to the first argument of
          the printf function in C or awk [see awk(1), printf(1), and the
          C-function printf(3S)].

          The output of date can be formatted by means of field descriptors
          in the format argument. Field descriptors take the form of a per-
          centage sign followed by a letter and are replaced in the output
          by their values. All characters that are not part of a field
          descriptor are copied to the output unmodified. The output is
          always terminated with a newline character.

          The following overview lists all legal field descriptors.
          Although the field descriptors %h and %b are essentially identi-
          cal, both descriptors have been retained for compatibility rea-
          sons.
          _________________________________________________________________
         %n     newline character                                      
         _____________________________________________________________
         %t     tab character                                          
         _____________________________________________________________
         %c     date and time in the default format of the current    
                    locale
         _____________________________________________________________
         %C     century (first two digits of the year, 00-99)          
         _____________________________________________________________
         %D     date in the format %m/%d/%y                            
         _____________________________________________________________
         %x     date in the format of the current locale              
         _____________________________________________________________
         %y     year (last two digits of the year, 00-99)              
         _____________________________________________________________
         %Y     year (all four digits of the year)                    
         _____________________________________________________________
         %m     month (01 to 12)                                      
         _____________________________________________________________
         %h     month (in letters, abbreviated) in the format of the  
                    current locale
         _____________________________________________________________
         %b     identical to %h                                        
         _____________________________________________________________
         %B     month (in letters, in full) in the format of of the    
                     current locale
         ____ _________________________________________________________
         %W     week number of the year (00 to 53, with Monday as the  
                      first day of the week). All days before the first Mon-
                      day in January belong to week 0.
         _______________________________________________________________
         %V     week number of the year (01 to 53, with Monday as the  
                 first day of the week). The first week in January is  
                 counted as week 1 if it contains at least 4 days. Oth-
                 erwise this week is counted as week 53 of the previous
                 year (in accordance with ISO 8601).                    
         _______________________________________________________________
         %U     week number of the year (00 to 53, with Sunday as the  
                 first day of the week). All days before the first Sun-
                 day in January belong to week 0.                      
         _______________________________________________________________
         %j     day of year (001 to 366)                              
         _______________________________________________________________
         %d     day of month (01 to 31)                                
         _______________________________________________________________
         %e     day of month (1 to 31, single-digit numbers preceded by
                 a blank)                                              
         _______________________________________________________________
         %a     abbreviated weekday name in the format of the current  
                 locale                                                
         _______________________________________________________________
         %A     full weekday name in the format of the current locale  
         _______________________________________________________________
         %w     day of week (0 to 6, Sunday = 0)                      
         _______________________________________________________________
         %u     day of week (1 to 7, Monday = 1)                      
         _______________________________________________________________
         %R     time in the format %H:%M                              
         _______________________________________________________________
         %T     time in the format %H:%M:%S                            
         _______________________________________________________________
         %X     time in the format of the current locale              
         _______________________________________________________________
         %r     time in a.m./p.m. notation, as %I:%M:%S %p            
         _______________________________________________________________
         %H     hour (00 to 23)                                        
         _______________________________________________________________
         %I     hour (01 to 12)                                        
         _______________________________________________________________
         %p     string containing ante-meridiem or post-meridiem      
                 indicator(a.m./p.m. affix) in the format of the current
                 locale.                                                
         _______________________________________________________________
         %M     minute (00 to 59)                                      
         _______________________________________________________________
         %S     second (00 to 61)                                      
         _______________________________________________________________
         %Z     timezone name, or no output if no timezone exists      
                 (governed by the value of the environment variable TZ,
                 see sh(1), "Standard shell variables").                
         _______________________________________________________________

          If an alternative representation is defined in your local
          environment (e.g. before and after Christ) you can call it using
          modified field descriptors. Modified field descriptors are in the
          form %Eletter or %Oletter. The modified field descriptors that
          can be used are listed in the overview below:

          If no alternative representation has been defined, all modified
          field descriptors output the value of the current unmodified
          field descriptors.
          _________________________________________________________________
         %Ec    date and time in the alternative format                
         _______________________________________________________________
         %EC    name of the time period (e.g. "year") in the alterna-  
                 tive representation                                    
         _______________________________________________________________
         %Ex    date in the alternative format                        
         _______________________________________________________________
         %EX    time in the alternative format                        
         _______________________________________________________________
         %Ey    year in which the time period in the alternative      
                 representation begins                                  
         _______________________________________________________________
         %EY    year in the alternative representation                
         _______________________________________________________________
         %Od    day of month in alternative numeric representation    
         _______________________________________________________________
         %Oe    day of month in alternative numeric representation    
         _______________________________________________________________
         %OH    hour (24-hour clock) in alternative numeric representa-
                 tion                                                  
         _______________________________________________________________
         %OI    hour (12-hour clock) in alternative numeric representa-
                 tion                                                  
         _______________________________________________________________
         %Om    month in alternative numeric representation

Fortsetzung: Datum ... schon wieder ...

Der folgende Beitrag wurde am 12. 01. 2000, 08:28 Uhr von Frank S. veröffentlicht.

Hier der 2te Teil des Postings.

         _______________________________________________________________
         %Om    month in alternative numeric representation            
         _______________________________________________________________
         %OM    minutes in alternative numeric representation          
         _______________________________________________________________
         %OS    seconds in alternative numeric representation          
         _______________________________________________________________
         %Ou    weekday in the alternative format (Monday = 1)        
         _______________________________________________________________
         %OU    week of the year in alternative numeric representation
                 (same as for %U)                                      
         _______________________________________________________________
         %OV    week of the year in alternative numeric representation
                 (same as for %V)                                      
         _______________________________________________________________
         %Ow    weekday in the alternative format (Sunday = 0)        
         _______________________________________________________________
         %OW    week of the year in alternative numeric representation
                 (same as for %W)                                      
         _______________________________________________________________
         %Oy    year in the alternative format                        
         _______________________________________________________________



   Format 2: Set system clock

     date[ -a[ -] ssss.fff][ -u][ new_date]

     This format is for the system administrator only.

     This format can be used to adjust the system clock or reset the date.

     -a[ -] ssss.fff
          Adjusts the system clock time by ssss.fff seconds, where fff
          represents fractions of a second. This adjustment can be positive
          or negative (-). The system's clock will be sped up or slowed
          down until it has changed by the specified amount (ssss may not
          exceed 2146).

     -u   Sets the date and time in Greenwich Mean Time (see option -u
          under Format 1).

     new_date
          date sets the date and time of the system clock to the specified
          value. The following can be entered for [mmdd]HHMM or
          mmddHHMM[cc]yy:

       ____________________________________________________________________
       mm       dd       HH       MM       cc       yy        
      ______________________________________________________________
       month     day       hour     minute   century   year (last
       (01 - 12) (01 - 31) (00 - 23) (00 - 59) minus 1   2 digits)  
      ______________________________________________________________

          mmdd not specified:

          date assumes that the specified time HHMM refers to the current
          date.

          cc not specified:

          date assumes that the specified date mmddHHMMyy refers to the
          current century.

     The system clock should only be set in single-user mode when all file
     systems have been unmounted. Changing the system clock may otherwise
     lead to inconsistencies in the file systems.



ERROR MESSAGES
   Format 2

     date: no permission.

     You have tried to set the system clock as a normal user. This
     privilege is reserved for the system administrator.

     date: bad conversion.

     You have attempted to set the system clock but have called date with
     an incorrect format.

ENVIRONMENT VARIABLES
     TZ   If defined, the environment variable TZ contains information on
          timezones. date uses TZ to determine the timezone and to convert
          from UTC (Universal Time Coordinated) to local time and vice
          versa.

          The value of TZ consists of

          -  the standard timezone

          -  the offset from UTC in hours

          -  if relevant, the summer timezone with information for conver-
             sions from standard time to summer time (daylight saving time)
             and back.

          A detailed description of TZ is provided under sh(1) in the sec-
          tion "Standard shell variables".

LOCALE
     The LC_MESSAGES environment variable governs the language in which
     message texts are displayed.

     The LC_TIME environment variable governs the language and the format
     in which the date and time and the values of date and time constants
     are displayed.

     LC_CTYPE governs character classes and character conversion (shift-
     ing).

     If LC_MESSAGES, LC_TIME or LC_CTYPE is undefined or is defined as the
     null string, it defaults to the value of LANG. If LANG is likewise
     undefined or null, the system acts as if it were not international-
     ized.

     If any of the locale variables has an invalid value, the system acts
     as if none of the variables were set.

     The LC_ALL environment variable governs the entire locale. LC_ALL
     takes precedence over all the other environment variables which affect
     internationalization.

EXAMPLES
     Example 1: Printing date and time (Format 1)

     If you call date without arguments at 17:00 hours EST on July 15,
     1991, and the system clock is set to the correct time, the following
     will be printed:

     Mon Jul 15 17:00:00 EST 1991

     The command:

     $ date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'

     generates the following output:

     DATE: 07/15/91
     TIME: 17:00:00 If you now call date without arguments at 17:05 hours
     EST on July 15, 1991, and the system clock is set to the correct time,
     the following will be printed:

     15 July 91

     Example 2: Setting the system clock (Format 2)

     You are working under the system administrator login root and want to
     set the date and time to 16:30 on March 17, 1991. To do this, you must
     first switch to single-user mode and unmount all file systems. You
     then enter:

     # date 0317163091

     If you are calling date in the year 1991, there is no need to specify
     the year.

SEE ALSO
     cal(1), sysadm(1M), ctime(3C), printf(3S), strftime(4), environ(5).

Fortsetzung: Datum ... schon wieder ...

Der folgende Beitrag wurde am 12. 01. 2000, 19:41 Uhr von Michael Schröpl veröffentlicht.

... und morgen postest Du das komplette Betriebssystem?

Sorry - aber eine solche Antwort, die zudem noch eine plattformspezifische Lösung liefert, während die von Calocybe kurz, knackig und portabel war, ist keine wirklich Hilfe.

© 1998-2013 SELFHTMLImpressumSoftware: Classic Forum 3.4