Page 1 of 1
Date in UTC?
Posted: Wed Apr 29, 2015 3:49 pm
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
Re: Date in UTC?
Posted: Wed Apr 29, 2015 6:50 pm
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
Re: Date in UTC?
Posted: Tue May 05, 2015 3:34 pm
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