in reply to Time Issues

Might help us to help you if you told us which timezone you are in. Or, more importantly, which timezone your computer is in.

Greenwich Mean Time never changes. Only local time changes.

Replies are listed 'Best First'.
Re^2: Time Issues
by Anonymous Monk on Mar 13, 2007 at 14:54 UTC
    The servers are on Eastern time... Since I have users from different time zones I am using the following code to get the server time ie eastern time always...
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time); my $gm_time = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday); my $server_time = $gm_time - (5*3600); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $time) = gmti +me($server_time); printf("%4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", $year + 1900, $mon + 1, $m +day, $hour, $min, $sec);
      The servers are on Eastern time

      That means nothing to me. Eastern what?

      But reading your code it seems you're in GMT-5, so you probably mean the Eastern US and just expect everyone in the world to realise that :-)

      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time); my $gm_time = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);

      Those two lines seem to just be the inverse of each other and can be replaced with:

      my $gm_time = time;

      In fact I think you are struggling towards

      use POSIX 'strftime'; print strftime '%Y-%m-%d %H:%M:%S', gmtime time - (5 * 3600);

      Fletch points out that it's the 5 that is wrong. For the next couple of weeks, it should be 4. Which is why it's easier to ensure that your system's Olson database is up to date and use "localtime" instead.

      Update: See, DST _is_ confusing. The difference between the East Coast of the US and the UK goes back to 5 hours in a few weeks time. But as ikegami points out the difference between the East Coast of the US and GMT will stay at 4 hours for quite a bit longer.

        For the next couple of weeks, it should be 4

        It's a stretch to call some date in November a "couple of weeks" away.

      You're manually converting a GMT epoch seconds to local incorrectly. During DST US/Eastern is GMT-4, not -5. If you'd use localtime this would be handled for you.