Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Epoch time conversion in CSV

by DrHyde (Prior)
on Sep 27, 2012 at 10:06 UTC ( #995961=note: print w/replies, xml ) Need Help??

in reply to Epoch time conversion in CSV

As others have said, you want to use DateTime, in particular the from_epoch constructor.

But be careful! You say "I'm in the GMT-5 timezone", which shows a fundamental misunderstanding of timezones. That could put you in New York, or it could put you in Lima, which are in different timezones. As I write this, it is 05:50 in New York but it is 04:50 in Lima, because one of them is in "daylight saving" time and the other is on sensible time.

You should always use timezone names, not offsets, and not abbreviations either as abbreviations like CST are ambiguous (is that CST in north America, or in Cuba, or China, or Australia? They differ by up to fifteen and a half hours!). You must use a timezone name like America/Lima to ensure you always get the correct conversion from epoch time to local time.

Finally, if you're writing out a data file in local time, always include the time zone. This will let other people in different time zones use the data correctly, but it will also help you use the data correctly. You won't have to remember whether you wrote that particular file in your local time, UTC, or something else.

Replies are listed 'Best First'.
Re^2: Epoch time conversion in CSV
by Tux (Abbot) on Sep 28, 2012 at 11:18 UTC

    I wholeheartedly agree

    until you happen to be using an old system tthat doesn't support named timezones :(

    GOOD $ env TZ="Europe/Dublin" date Fri 28 Sep 2012 12:13:03 IST GOOD $ env TZ="Europe/Amsterdam" date Fri 28 Sep 2012 13:13:14 CEST BAD $ env TZ="Europe/Berlin" date Fri Sep 28 11:14:04 Europe/Berlin 2012 BAD $ env TZ="Europe/Amsterdam" date Fri Sep 28 11:14:12 Europe/Amsterdam 2012 BAD $ env TZ="Europe/Dublin" date Fri Sep 28 11:14:38 Europe/Dublin 2012 BAD $ env TZ=MET-1METDST date Fri Sep 28 13:14:50 METDST 2012 BAD $ env TZ=GMT-5GMTDST date Fri Sep 28 17:14:56 GMTDST 2012

    Enjoy, Have FUN! H.Merijn
      I thought that even then DateTime would support them.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995961]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-06-23 05:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.