Logic Machine Forum
time in lua - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: time in lua (/showthread.php?tid=1969)



time in lua - rocfusion - 14.03.2019

Hi,

I have a device it which returns a time stamp,  in the follow format:   1552587707032


Now I need to send the current time back in the same format.  os.time generates a time like 1552589984  which is 3 digits less that what the device is expecting.  Does anybody have an idea how to get the same format?

Thanks,

Roger


RE: time in lua - Erwin van der Zwart - 14.03.2019

Hi Roger,

I think it's a UNIX microtime format with milliseconds included.

I would try to do this to make it os.time() format (seconds):

Code:
value = 1552587707032
value = math.floor((value/1000))
log(value) --> 1552587707

BR,

Erwin


RE: time in lua - rocfusion - 14.03.2019

ok, how would I send the time back in that format? just multiply by a 1000


RE: time in lua - admin - 15.03.2019

Code:
ts, tu = os.microtime()
time = ts * 1000 + math.floor(tu / 1000)



RE: time in lua - rocfusion - 15.03.2019

Hi, thank you that works...

Thx
Roger