1. timestamp in any timezone
- Posted by petelomax Feb 19, 2018
- 1006 views
I need a timestamp in seconds since 1/1/1970 0:0:0 UTC
The problem I'm getting is that it works here, in GMT, but the same code running in Texas is 6 hours (21600 seconds) adrift.
This is the (phix only) code I'm currently using:
include builtins\timedate.e timedate t0 = parse_date_string("1/1/1970 UTC",{"D/M/YYYY tz"}) function timestamp() sequence d = date() string res = sprintf("%d",{timedate_diff(t0,d,DT_SECOND)}) return res end function ?timestamp()
Any suggestions?
2. Re: timestamp in any timezone
- Posted by jimcbrown (admin) Feb 19, 2018
- 1012 views
I need a timestamp in seconds since 1/1/1970 0:0:0 UTC
The problem I'm getting is that it works here, in GMT, but the same code running in Texas is 6 hours (21600 seconds) adrift.
This is the (phix only) code I'm currently using:
<snip> sequence d = date() string res = sprintf("%d",{timedate_diff(t0,d,DT_SECOND)}) <snip>
Any suggestions?
The docs don't explicitly mention this, http://openeuphoria.org/docs/std_datetime.html#_1104_date
but looking at the OE implementation http://scm.openeuphoria.org/hg/euphoria/file/66986691c7b0/source/be_runtime.c#l3549 , we see that date() returns the current local time, not the current GMT time.
I can't speak to how Phix implements date() but OE's version hasn't changed from the RDS Euphoria days, so ...
For OE, I'd recommend using now_gmt() instead.
http://openeuphoria.org/docs/std_datetime.html#_1121_now_gmt
http://scm.openeuphoria.org/hg/euphoria/file/66986691c7b0/include/std/datetime.e#l553
Aside from some C routine wrappers, now_gmt() is 100% Euphoria so you can probably crib the code without too much trouble for Phix.