Leser: 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use strict; use POSIX qw(mktime tzset); print "Content-type: text/html\n\n"; my $anfang_in = '29.10.2011 08:30'; print "Anfang: '$anfang_in'<br>"; my ($dd, $dm, $dy, $th, $tm, $ts) = split(/[\.: ]/, $anfang_in); $dm = $dm - 1; $dy = $dy - 1900; $ts = 0; my $time = mktime($ts, $tm, $th, $dd, $dm, $dy); print "Time: '$time' ($ts/$tm/$th/$dd/$dm/$dy)<br>"; my ($isdst) = (localtime($time))[-1]; if ($isdst) { $time = $time - 2*60*60; } else { $time = $time -1*60*60; } # else ($ts, $tm, $th, $dd, $dm, $dy) = (localtime($time))[0..5]; $anfang = sprintf("%04d.%02d.%02d %02d:%02d:%02d", $dy + 1900, $dm + 1, $dd, $th, $tm, $ts); my ($std, $dst) = POSIX::tzname(); print "TZ: '$std/$dst'<br>";
QuoteAnfang: '29.10.2011 08:30'
Time: '1319869800' (0/30/08/29/9/111)
TZ: 'CET/CEST'
QuoteAnfang: '29.10.2011 08:30'
Time: '1319873400' (0/30/08/29/9/111)
TZ: 'CET/CEST'
1 2 3 4
$anfang_in = '29.10.2011 08:30'; @date = split /[.:\s]/,$anfang_in; # Datum und Zeit in MySQL-Format $anfang_in = sprintf ("%4d-%02d-%02d %02d:%02d:00", reverse(@date[0..2]), @date[3,4]);
1 2 3 4
my $time = mktime($ts, $tm, $th, $dd, $dm, $dy); print "Time: '$time' ($ts/$tm/$th/$dd/$dm/$dy)<br>"; ($ts, $tm, $th, $dd, $dm, $dy) = (localtime($time))[0..5]; print "Time: '$time' ($ts/$tm/$th/$dd/$dm/$dy)<br>";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl use strict; use POSIX qw(mktime); my $anfang_in = '29.10.2011 08:30'; print "Anfang: '$anfang_in'\n"; print "TZ: ", (join " | ",POSIX::tzname()), "\n"; print "ENV TZ: ", $ENV{TZ}, "\n"; my ($dd, $dm, $dy, $th, $tm, $ts) = split(/[\.: ]/, $anfang_in); my $time = POSIX::mktime($ts, $tm, $th, $dd, $dm-1, $dy-1900); print "\$time aus POSIX::mktime (Ver. $POSIX::VERSION): $time\n", "Local: " . localtime($time) . "\n", "GMT: " . gmtime($time) . "\n",
2011-01-10T16:16:16 GwenDragontzname liefert übrigens immer GMT, wenn die Umgebungsvariable TZ nicht gesetzt ist.
POSIX::tzname ist also keine Möglichkeit herauszufinden, welche Timezone wirklich benutzt wird.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@svr ~] perl
use Date::Language;
print "\n", "Date::Parse ", '#' x 20, "\n";
$anfang_in = '29 Okt 2011 8:30';
print "Anfang: '$anfang_in'\n";
my $lang = Date::Language->new('German');
my $time2 = $lang->str2time($anfang_in);
#my ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($anfang_in);
print "str2time: $time2\n";
print "time2str: ", $lang->time2str("%d %b %Y %R %Z",$time2),"\n";
__END__
Date::Parse ####################
Anfang: '29 Okt 2011 8:30'
str2time: 1319869800
time2str: 29 Okt 2011 08:30 MEST