On Wed, Apr 2, 2008 at 2:02 AM, Jeff Pang <[EMAIL PROTECTED]> wrote:
> On 4/2/08, Richard Lee <[EMAIL PROTECTED]> wrote:
>  > What is the best way to indicate past hour from current time without
>  > using a module?
>  >
>  > so if it's 12:00, then 11:00-12:00
>  >
>
>  I'd prefer using POSIX module since it's a built-in perl module.
>  The code would be simple,
>
>  use strict;
>  use POSIX 'strftime';
>
>  print get_time(time - 3600),"-",get_time(),"\n";
>
>  sub get_time {
>     my $timestamp = shift || time;
>     return strftime("%H:%M",localtime($timestamp));
> }

This is one of those seemingly simple questions that turns out to be
much more complicated than you originally think.  For instance, what
is one hour less than 2008-03-09 03:00:00?  If you answered 2008-03-09
02:00:00 you would be wrong in the USA as that hour does not exist.
Daylight Saving Time kicks in on the second Sunday of March (for now
at least), so the right answer is 2008-03-09 01:00:00.  These sort of
caveats make working with dates and times a pain.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to