in reply to Re: time as number
in thread time as number
It should be kept in mind that the POSIX module doesn't specify which %Formats strftime should support. The native Win32 version for instance doesn't support at least one that the Cygwin libraries do. From what i've seen from the web the strftime formats vary quite a bit. Don't expect them all to work. I put this together from one of the longest lists I could find on the web.
use POSIX qw(strftime); use Text::Wrap; %fmt = ( '' => '', '%%' => q"A literal `%' character.", '%+' => 'The date and time in date(1) format. (TZ)', '%a' => 'The abbreviated weekday name according to the current loc +ale.', '%A' => 'The full weekday name according to the current locale.', '%b' => 'The abbreviated month name according to the current local +e.', '%B' => 'The full monthname according to the current locale.', '%C' => 'The century number (year/100) as a 2-digit integer. (SU)' +, '%c' => 'The preferred date and time representation for the curren +t locale.', '%d' => 'The day of the month as a decimal number (range 01 to 31) +.', '%D' => 'Equivalent to %m/%d/%y. (Yecch - for Americans only. Amer +icans should note t' . 'hat in other countries %d/%m/%y is rather common. This means +that in interna' . 'tional context this format is ambiguous and should not be use +d.) (SU)', '%F' => 'Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99) +', '%G' => 'The ISO 8601 year with century as a decimal number. The +4-digit year corresp' . 'onding to the ISO week number (see %V). This has the same for +mat and value a' . 's %y, except that if the ISO week number belongs to the previ +ous or next yea' . 'r, that year is used instead. (TZ)', '%g' => 'Like %G, but without century, i.e., with a 2-digit year ( +00-99). (TZ)', '%h' => 'Equivalent to %b. (SU)', '%H' => 'The hour as a decimal number using a 24-hour clock (range + 00 to 23).', '%I' => 'The hour as a decimal number using a 12-hour clock (range + 01 to 12).', '%j' => 'The day of the year as a decimal number (range 001 to 366 +).', '%k' => 'The hour (24-hour clock) as a decimal number (range 0 to +23); single digits ' . 'are preceded by a blank. (See also %H.) (TZ)', '%l' => 'The hour (12-hour clock) as a decimal number (range 1 to +12); single digits ' . 'are preceded by a blank. (See also %I.) (TZ)', '%m' => 'The month as a decimal number (range 01 to 12).', '%M' => 'The minute as a decimal number (range 00 to 59).', '%n' => 'A newline character. (SU)', '%p' => q"Either `AM' or `PM' according to the given time value, +or the corresponding " . q"strings for the current locale. Noon is treated as `pm'and m +idnight as `am'.", '%P' => q"Like %p but in lowercase: `am' or `pm' or a correspondin +g string for the cur" . q"rent locale. (GNU)", '%r' => q"The time in a.m. or p.m. notation. In the POSIX locale t +his is equivalent to" . q" `%I:%M:%S %p'. (SU)", '%R' => 'The time in 24-hour notation (%H:%M). (SU) For a version +including the secon' . 'ds, see %T below.', '%S' => 'The second as a decimal number (range 00 to 61).', '%s' => 'The number of seconds since the Epoch, i.e., since 1970-0 +1-01 00:00:00 UTC. ' . '(TZ)', '%T' => 'The time in 24-hour notation (%H:%M:%S). (SU)', '%t' => 'A tab character. (SU)', '%u' => 'The dayof the week as a decimal, range 1 to 7, Monday bei +ng 1. See also %w. ' . '(SU)', '%U' => 'The week number of the current year as a decimal number, +range 00 to 53, sta' . 'rting with the first Sunday as the first day of week 01. See +also %V and %W.', '%V' => 'The ISO8601:1988 week number of the current year as a dec +imal number, range ' . '01 to 53, where week1 is the first week that has at least 4 d +ays in the curr' . 'ent year, and with Monday as the first day of the week. See a +lso %U and %W. ' . '(SU)', '%w' => 'The dayof the week as a decimal, range 0 to 6, Sunday bei +ng 0. See also %u.', '%W' => 'The week number of the current year as a decimal number, +range 00 to 53, sta' . 'rting with the first Monday as the first day of week 01.', '%X' => 'The preferred time representation for the current locale +without the date.', '%x' => 'The preferred date representation for the current locale +without the time.', '%Y' => 'The year as a decimal number including the century.', '%y' => 'The year as a decimal number without a century (range 00 +to 99).', '%Z' => 'The time zone or name or abbreviation.', '%z' => 'The time-zone as hour offset from GMT. Required to emit R +FC822-conformant da' . 'tes (using "%a, %d %b %Y %H:%M:%S %z"). (GNU)', ); print "\nGood on $^O\n----------------\n", @bad; foreach my $fmt ( sort { lc $a cmp lc $b } keys %fmt ) { my $result = strftime( $fmt, localtime $^T ); (my $ofmt=$fmt)=~s/^%(.+)$/\%\#$1/; my $result2 = strftime( $ofmt, localtime $^T ); my $str = join '', "$fmt '$result' ($ofmt '$result2')\n", wrap( "\ +t", "\t", $fmt{$fmt} ), "\n"; if ($result) { print $str; } else { push @bad, $fmt; } } print "\nBad on $^O\n----------------\n@bad\n";
Which outputs on Perl AS 633
Good on MSWin32 ---------------- %% '%' (%#% '%') A literal `%' character. %a 'Sat' (%#a 'Sat') The abbreviated weekday name according to the current locale. %A 'Saturday' (%#A 'Saturday') The full weekday name according to the current locale. %B 'February' (%#B 'February') The full monthname according to the current locale. %b 'Feb' (%#b 'Feb') The abbreviated month name according to the current locale. %c '02/22/2003 12:03:45 AM' (%#c 'Saturday, February 22, 2003 12:03:45 + AM') The preferred date and time representation for the current locale. %d '22' (%#d '22') The day of the month as a decimal number (range 01 to 31). %H '00' (%#H '0') The hour as a decimal number using a 24-hour clock (range 00 to 23). %I '12' (%#I '12') The hour as a decimal number using a 12-hour clock (range 01 to 12). %j '053' (%#j '53') The day of the year as a decimal number (range 001 to 366). %m '02' (%#m '2') The month as a decimal number (range 01 to 12). %M '03' (%#M '3') The minute as a decimal number (range 00 to 59). %p 'AM' (%#p 'AM') Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale. Noon is treated as `pm'and midnight as `am'. %S '45' (%#S '45') The second as a decimal number (range 00 to 61). %U '07' (%#U '7') The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W. %W '07' (%#W '7') The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01. %w '6' (%#w '6') The dayof the week as a decimal, range 0 to 6, Sunday being 0. See also %u. %x '02/22/2003' (%#x 'Saturday, February 22, 2003') The preferred date representation for the current locale without the time. %X '12:03:45 AM' (%#X '12:03:45 AM') The preferred time representation for the current locale without the date. %Y '2003' (%#Y '2003') The year as a decimal number including the century. %y '03' (%#y '3') The year as a decimal number without a century (range 00 to 99). %z 'W. Europe Standard Time' (%#z 'W. Europe Standard Time') The time-zone as hour offset from GMT. Required to emit RFC822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z"). (GNU) %Z 'W. Europe Standard Time' (%#Z 'W. Europe Standard Time') The time zone or name or abbreviation. Bad on MSWin32 ---------------- %+ %C %D %F %g %G %h %k %l %n %P %r %R %s %t %T %u %V
|
|---|