use Time::Piece; use Time::Seconds; use POSIX qw(strftime); sub print_tp { my $tp = shift; printf("date : %s\ntzoffset: %d\nepoch : %d\nstrftime: %s\n\n", $tp->strftime('%Y-%m-%d %T'), $tp->tzoffset, $tp->epoch, strftime('%Y-%m-%d %T', localtime($tp->epoch)), ); } print "Time::Piece ",$Time::Piece::VERSION,"\n"; my $tp; $tp = Time::Piece->strptime("2011-01-01", "%Y-%m-%d"); print_tp($tp); $tp = localtime( Time::Piece->strptime("2011-01-01", "%Y-%m-%d") ); print_tp($tp); $tp = $tp + ONE_DAY; print_tp($tp);
ã¾ãããã
$tp = Time::Piece->strptime("2011-01-01", "%Y-%m-%d"); print_tp($tp); â date : 2011-01-01 00:00:00 tzoffset: 0 epoch : 1293840000 strftime: 2011-01-01 09:00:00
ãã£ããä½ãèããã« strptime ã使ãã¨ãç°å¢å¤æ°TZãã©ãã§ãããå¾ãããã¤ã³ã¹ã¿ã³ã¹ã®ã¿ã¤ã ã¾ã¼ã³ã¯GMT(UTC)ã«ãªãã¾ãããã®ãã¨ãå¿ã㦠$tp->epoch ã®å¤ã使ãã¨ãæ¥æ¬ã ã¨9æéãããçµæã«ãªã£ã¦ãã¾ãã¾ããä¾ãã°ãæ¥æ¬¡ã®çµ±è¨å¦çã§æ°å¤ãã©ããåããªãã¨ãããã
ããã¯ã
$tp = localtime( Time::Piece->strptime("2011-01-01", "%Y-%m-%d") ); print_tp($tp); â date : 2011-01-01 00:00:00 tzoffset: 32400 epoch : 1293807600 strftime: 2011-01-01 00:00:00
ã®ããã«localtime()ããã¤ã³ã¹ã¿ã³ã¹ã使ãã°OKã§ãã
ã¾ãããã®ããã«ã
$tp = $tp + ONE_DAY; print_tp($tp); â date : 2011-01-02 00:00:00 tzoffset: 32400 epoch : 1293894000 strftime: 2011-01-02 00:00:00
å ã®ã¤ã³ã¹ã¿ã³ã¹ã«ã¿ã¤ã ã¾ã¼ã³ãã¤ãã¦ããã°ããããæ¼ç®ããã¦ãã¿ã¤ã ã¾ã¼ã³ã®æ å ±ã¯ã¡ããã¨åãç¶ããã¾ãã
ããã¾ã§ã§ã²ã¨ãããã
次ã
åãã¹ã¯ãªãããªã®ã«ãã¡ãã㨠localtime() ãã¦ããã®ã«ãåã¯å ¨ç¶æªããªãã¯ããªã®ã«ããªããç°å¢ã«ãã£ã¦æå¾ ããããã«ã¿ã¤ã ã¾ã¼ã³ãã¤ããªãã±ã¼ã¹ããã£ãã®ã§ãã
ãããªæãã«ã
$tp = localtime( Time::Piece->strptime("2011-01-01", "%Y-%m-%d") ); print_tp($tp); â date : 2011-01-01 00:00:00 tzoffset: 0 epoch : 1293840000 strftime: 2011-01-01 09:00:00
ããããã¿ãã¨ãTime::Piece ã®ãã¼ã¸ã§ã³ãç°ãªããããããããããã¿ãã¨ãChangesã«ãããªè¨è¿°ãããã
1.16 - Implement %z for the internal implementation of strptime(). Unfortunately this doesn't get picked up everywhere, so there are no tests for it (yet - patches welcome).
Time::Piece 1.15ãå«ã¿ããããå¤ããã¼ã¸ã§ã³ã使ã£ã¦ãå ´åã¯ãçªããæãæ¨ã¦ã¦æ©æ¥ã«æ°ãããã¼ã¸ã§ã³ãå ¥ãã¾ãããï¼ï¼
1.15_01ããã¡ãã¯ç¢ºèªãã¦ãªãã®ã§ãããPerlæ¬ä½ã«å梱ããããã¼ã¸ã§ã³ã¯çµæ§å±ããã®ã§æ°ãã¤ãã¦ãã
$ corelist -a Time::Piece Time::Piece was first released with perl v5.9.5 v5.9.5 1.11_02 v5.10.0 1.12 v5.10.1 1.15 v5.11.0 1.15 v5.11.1 1.15 v5.11.2 1.15 v5.11.3 1.15 v5.11.4 1.15 v5.11.5 1.15 v5.12.0 1.15_01 v5.12.1 1.15_01 v5.12.2 1.15_01 v5.13.0 1.15_01 v5.13.1 1.15_01 v5.13.2 1.15_01 v5.13.3 1.20_01 v5.13.4 1.20_01 v5.13.5 1.20_01 v5.13.6 1.20_01 v5.13.7 1.20_01