This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Time Format
#1
Hello, could anybody tell me how to format LM time to this format and vise versa?
Code:
/Date(1670926903419+0100)/
Reply
#2
It's a timestamp in milliseconds with timezone.
Current date/time to string conversion:
Code:
tz = os.date('%z')
ts, tu = os.microtime()

str = string.format('/Date(%d%03d%s)/', ts, tu / 1000, tz)
log(str)

Convert string to date/time:
Code:
str = '/Date(1670926903419+0100)/'

time = tonumber(str:match('%d+'))

ts = math.floor(time / 1000) -- timestamp in seconds
tm = time % 1000 -- millisecond part of the timestamp

date = os.date('%c', ts) -- readable date from timestamp

log(date, ts, tm)
Reply
#3
(12.12.2022, 10:36)admin Wrote: It's a timestamp in milliseconds with timezone.
Current date/time to string conversion:
Code:
tz = os.date('%z')
ts, tu = os.microtime()

str = string.format('/Date(%d%03d%s)/', ts, tu / 1000, tz)
log(str)

Convert string to date/time:
Code:
str = '/Date(1670926903419+0100)/'

time = tonumber(str:match('%d+'))

ts = math.floor(time / 1000) -- timestamp in seconds
tm = time % 1000 -- millisecond part of the timestamp

date = os.date('%c', ts) -- readable date from timestamp

log(date, ts, tm)


Thanks!

And if I wanted to at for example 24h to the "str" string, to use as a from-to range?
Reply
#4
You can add 86400 to ts variable.
Reply


Forum Jump: