Hi,
I unterstand that datalogger data timestamp can be easily converted to epoch time in CR Basic. Vice visa, is there any way to convert with CR Basic code from epoch time to normal date/time format? For example "1640348700" to "Friday, 24 December 2021 12:25:00".
Also how to change epoch time in sec to msec, because when I multiply with 1000 it become NAN.
Thanks in adavance.
Best regards,
Thein
The SecsSince1990() instruction works in both directions. You can provide seconds in a variable of type Long, and receive a string. I think format option 2 is what you want.
A Long cannot contain enough digits to hold the milliseconds. In its binary data tables, the datalogger keeps the fractional seconds is a second 4 byte value.
Hi JDavis,
Thanks a lot. I'll try it out.
This post is under review.
Hi JDavis,
Thanks again for your explanation. Actually I need for Since Epoch (Since1970), so I minus secs for 20 years. It works out well with the Seconds. But it did not work exactly with miliseconds. I've got API call data as follow:- the correct return should be 21/09/2022 16:15:00 instead I got as follows and keep varrying within plus or minus 1 to 150 secs for each scan:-
MidString(5): "timestamp": 1663748099999}], "ok": true} 'API parse
Time_Stamp_Str: 21/09/2022 16:14:56
The code to get this Time_Stamp_Str is as follows:-
SplitStr (Time_Stamp,MidString(5),CHR(34)+"timestamp"+CHR(34)+CHR(58)+" ",1,0) Time_Stamp = (Time_Stamp / 1000) + 0.001 ' mSec to Sec Since Epoch GMT Time_Stamp_Str = SecsSince1990(Time_Stamp - 631152000 + 28800,3) ' minus 20yrs in Sec for 1970 & plus 8 hrs in Sec for Malaysian Time
Is there any way to correctly calculate these miliseconds value?
Best regards,
Thein