Date in UTC?

Post Reply
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Date in UTC?

Post by tz8 »

All,

i want to dump the a Date (in my case the lastModified of a file) to String, but in UTC.

Any suggestions on how to convert taking DST into account? I fear this is another call to an external programm...

Cheers,

tz8
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Date in UTC?

Post by dkelly »

If you only have a few timezones to convert from you could parse the string and do adjustment yourself in Javascript. Otherwise, port something like https://github.com/mde/timezone-js to Switch
bens
Member
Posts: 130
Joined: Thu Mar 03, 2011 10:13 am

Re: Date in UTC?

Post by bens »

I would suggest you reconsider the need for using UTC. There is no reliable way to know the last modification date of a file when working with different time zones and/or different file systems. At best you'll get correct results only when working on a single system, at worst you'll get completely unreliable results - correct for some files, wrong for others.

If you really do need this, then I strongly suggest either using an external program (e.g. the Mac "date" command, although it might be hard to find the exact parameters you need) or use someone else's code, as dkelly suggested. What you really don't want to do is write your own code to work with timezones, because that way madness lies, as the bard says.

Computerphile has a fun video about this: https://www.youtube.com/watch?v=-5wpm-gesOY
Post Reply