April 10, 2019
dateDiff/dateconvert problems when trying to create epoch times
Like
(0)
Comments
(1)
0
1
My local server’s timezone is set to UTC-8 – https://www.screencast.com/t/1qqid95lR3v
I need to create epoch time for UTC so I’m trying to use the following function:
#DateDiff(“s”, “January 1 1970 00:00:00”, dateconvert(“local2utc”, now()))#
The dateconvert function does not compute the correct time using any combination.
Here is example code:
<cfset utcTime = dateconvert("local2utc", now())> <cfoutput> now: #now()# <br>local2utc: #utcTime# <br>epoch (now){currentTime:#DateDiff("s", "January 1 1970 00:00:00", now())#} <br/>epoch (local2utc){currentTime:#DateDiff("s", "January 1 1970 00:00:00", dateconvert("local2utc", now()))#} <br>epoch (utcTimeVar){currentTime:#DateDiff("s", "January 1 1970 00:00:00", utcTime)#} </cfoutput>
Here is that code’s output:
now: {ts '2019-04-10 10:54:44'} local2utc: {ts '2019-04-10 17:54:44'} epoch (now){currentTime:1554890084} epoch (local2utc){currentTime:1554890084} epoch (utcTimeVar){currentTime:1554890084}
Notice that all 3 epoch times are identical. The dateconvert value is not being taken into account, even with the utcTimeVar, which is baffling.
See it live here: http://l.thcguard.com/gettimetest.cfm
Please give me guidance!