So im trying to make a script that gets a timestamp from productinfo of a model and takes that value away from os.time() so i know how long ago the model was updated. I have no idea how i would do this and not sure if its even possible, if it is please tell me. Thanks!
That timestamp you posted is in ISO-8601.
After some Googling, I found that someone made their own function to convert this into UST (Unix Standard Time), which is what os.time()
returns time as.
-- https://forum.rainmeter.net/viewtopic.php?t=23486 function TimeStamp(dateStringArg) local inYear, inMonth, inDay, inHour, inMinute, inSecond, inZone = string.match(dateStringArg, '^(%d%d%d%d)-(%d%d)-(%d%d)T(%d%d):(%d%d):(%d%d)(.-)$') local zHours, zMinutes = string.match(inZone, '^(.-):(%d%d)$') local returnTime = os.time({year=inYear, month=inMonth, day=inDay, hour=inHour, min=inMinute, sec=inSecond, isdst=false}) if zHours then returnTime = returnTime - ((tonumber(zHours)*3600) + (tonumber(zMinutes)*60)) end return returnTime end
And you can use it like this:
local t = "2017-09-17T19:25:27.9843202Z" print(TimeStamp(t)) -- 1505676327, which seems about right.
This is really easy using multiplication.
function ConvertYear(value) --converts a year to seconds return value *3.154e+7 end function ConvertMonth(value) --converts a month into seconds return value * 2.628e+6 end
and so on. Also, months may not be accurate as they can have 29 days, 30 days, or 31. Why would you want to convert this to seconds? It is harder to read when it is in seconds.
Hope this helps!