Datum ... schon wieder ...
Poldi
- perl
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.
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
Hallo Lehrer
»»seid doch so nett, mischt euch doch selber einfach mit ein und geht mit eueren Schuelern die Hausaufgaben durch - vielleicht sogar im Chat ;-)
Nö, also das muss nun wirklich nicht sein. Aber der liebe Stefan freud sich immer, wenn er viele Mails von lieben Schülern (und Lehrern) bekommt.
Also schickt ruhig ihm das Zeug ;-)
Grüße
Daniel
PS: Stefan, nix für ungut, aber ich kann nicht noch "Informatik"untericht im Chat brauchen. Irgendwo muss schluss sein ;-)
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).
... 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.