Date and Time

Hi,

Its not clear to me if this function gets seconds since epoch until now GMT(UTC) or until local time.

I assume the epoch itself was a fixed UTC point.

os.time

And again, if call it with a table, like this;

epochSeconds = os.time( { year = 2015, month = 12, day = 25, hour = 0, min = 0, sec = 0, isdst= false } )

Am I getting the seconds from the epoch till xmas day GMT, or seconds from the epoch till xmas local time? 

Many thanks

You can figure this out as follows:

print( os.time( { year = 1970, month = 1, day = 1, hour = 0, min = 0, sec = 0, isdst = false } ))

This prints 28800 == 8 hours  (I’m in Oregon, which is UTC + 8)

i.e. This prints out the time (in seconds) since 1970 UTC + 0, but for my time zone which is +8 hours.

So, your example will print out:  

Time (in seconds) since January 1, 1970 0:00 UTC + 0

till

December 25, 2015 0:00 UTC +/- your time zone delta.

I hope this helps.

PS - And no Daylight Savings Time taken into account.

Hi thanks.

Is there a way to make the call so that it does not adjust by adding / subtracting the timezone delta?

I want all dates and times in GMT not the users local time.

the os.date function DOES give me GMT if I have “!” as the first character in the format string (as per the docs), feels like it should work “in the other direction” as well.

alternatively if i could know the offset, I could just add/subtract that many seconds from my epoch integer.

This gives the difference between GMT and local.

function U.makeTimeStamp(dateString)   local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d?%d?)%:?(%d?%d?)"   local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin =   dateString:match(pattern)   local timestamp = os.time( {year=year, month=month, day=day, hour=hour, min=minute, sec=seconds, isdst=false} )   return timestamp end local timeGMT = U.makeTimeStamp( os.date("!%Y-%m-%dT%XZ") ) local timeLocal = U.makeTimeStamp( os.date("%Y-%m-%dT%XZ") ) -- positive local is ahead, negative local is behind local timeAdjustment = timeLocal - timeGMT print ("GMT: "..timeGMT.." LOCAL: "..timeLocal.." ADJ: "..timeAdjustment) GMT: 1438894127 LOCAL: 1438897727 ADJ: 3600

Thanks for that self answer and code post.  I’ll put that in my toolbox!

You can figure this out as follows:

print( os.time( { year = 1970, month = 1, day = 1, hour = 0, min = 0, sec = 0, isdst = false } ))

This prints 28800 == 8 hours  (I’m in Oregon, which is UTC + 8)

i.e. This prints out the time (in seconds) since 1970 UTC + 0, but for my time zone which is +8 hours.

So, your example will print out:  

Time (in seconds) since January 1, 1970 0:00 UTC + 0

till

December 25, 2015 0:00 UTC +/- your time zone delta.

I hope this helps.

PS - And no Daylight Savings Time taken into account.

Hi thanks.

Is there a way to make the call so that it does not adjust by adding / subtracting the timezone delta?

I want all dates and times in GMT not the users local time.

the os.date function DOES give me GMT if I have “!” as the first character in the format string (as per the docs), feels like it should work “in the other direction” as well.

alternatively if i could know the offset, I could just add/subtract that many seconds from my epoch integer.

This gives the difference between GMT and local.

function U.makeTimeStamp(dateString)   local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d?%d?)%:?(%d?%d?)"   local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin =   dateString:match(pattern)   local timestamp = os.time( {year=year, month=month, day=day, hour=hour, min=minute, sec=seconds, isdst=false} )   return timestamp end local timeGMT = U.makeTimeStamp( os.date("!%Y-%m-%dT%XZ") ) local timeLocal = U.makeTimeStamp( os.date("%Y-%m-%dT%XZ") ) -- positive local is ahead, negative local is behind local timeAdjustment = timeLocal - timeGMT print ("GMT: "..timeGMT.." LOCAL: "..timeLocal.." ADJ: "..timeAdjustment) GMT: 1438894127 LOCAL: 1438897727 ADJ: 3600

Thanks for that self answer and code post.  I’ll put that in my toolbox!