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.

os.time()
#1
Hello,

can't find correct answer, think LUA guru can help..

now = os.time() returns me 1543929730 

How correct understand this value? How convert to normal time? (hours, minutes, seconds, milliseconds?) If I want to work with minutes, or seconds, how convert this value? Is it UNIX time stamp? Please explain a little, need to use in different timers.

Sorry for basic questions just learning LUA.
Reply
#2
It is UNIX timestamp, number of seconds from January 1st, 1970. You can use os.date(fmt, time) to convert to human-readable date. If you need a relative value (hours, minutes etc between two timestamps) then you need to convert manually using / and % math operators.
Reply
#3
Ok, thanks, will study more deeply.
Reply
#4
(04.12.2018, 13:50)admin Wrote: It is UNIX timestamp, number of seconds from January 1st, 1970. You can use os.date(fmt, time) to convert to human-readable date. If you need a relative value (hours, minutes etc between two timestamps) then you need to convert manually using / and % math operators.

Hi admin, is there any way to get UNIX 13-digit timestamp rather than the 10-digit?
Reply
#5
I assume you need this: os.microtime()
Reply
#6
(11.03.2023, 07:25)Erwin van der Zwart Wrote: I assume you need this: os.microtime()

No sir, it produce the same result

Code:
Code:
-- os.time() -- 10-digit timestamp
os_time = os.time()
log('os_time: '..os_time)

-- os.microtime()
os_micro = os.microtime()
log('os_microtime: '..os_micro)
 
Result: 
Code:
os time 13-digit try 11.03.2023 18:45:48
* string: os_time: 1678556748
os time 13-digit try 11.03.2023 18:45:48
* string: os_microtime: 1678556748
Reply
#7
Use this:
Code:
tsec, tusec = os.microtime()
tmsec = tsec * 1000 + math.floor(tusec / 1000)
log(tmsec)
Reply
#8
(13.03.2023, 07:48)admin Wrote: Use this:
Code:
tsec, tusec = os.microtime()
tmsec = tsec * 1000 + math.floor(tusec / 1000)
log(tmsec)

It worked, thanks
Reply


Forum Jump: