in reply to Re^3: Date Time problem.
in thread Date Time problem.
Previously written example:
# Set your timezone to America/New_York before running. # In this time zone, DST ends on Nov 2, 2008 at 2:00 AM. # "Sets" the current time to 5 seconds past midnight on Oct 28, 2008. use Time::Local qw( timelocal ); my $time = timelocal(5,0,0,28,10-1,2008); use POSIX; print( strftime( "%m-%d\n", localtime( (24*60*60) * $_ + $time ) ) ) for 1..30;
Output
10-29 10-30 10-31 11-01 11-02 \ 11-02 seen twice 11-02 / 11-03 11-04 11-05 11-06 11-07 11-08 11-09 11-10 11-11 11-12 11-13 11-14 11-15 11-16 11-17 11-18 11-19 11-20 11-21 11-22 11-23 11-24 11-25 11-26 > 11-27 never seen
You don't need any inefficient code to do it right, so you might as well do it right. Sewi showed a way that will probably always work. The following will always work:
use Time::Local qw( timegm ); use POSIX qw( strftime ); my $date = timegm(localtime); $date += 24*60*60; print(strftime("%Y%m%d\n", gmtime($date)));
GMT always has 24*60*60 seconds per day. Note the result is still local time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Date Time problem.
by Marshall (Canon) on Sep 05, 2009 at 06:35 UTC | |
by ikegami (Patriarch) on Sep 05, 2009 at 07:17 UTC | |
by Marshall (Canon) on Sep 05, 2009 at 08:21 UTC | |
by ikegami (Patriarch) on Sep 05, 2009 at 18:42 UTC | |
by Marshall (Canon) on Sep 08, 2009 at 00:23 UTC |