Converting native time (and date) on ESP32 to system that is using javascript to display date? #16336
Replies: 2 comments
-
The epoch is not necessarily the same as POSIX (UNIX). ESP32 port starts at 2000/1/1. The built-in time module ( |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yeah... that explains the 1994 reference... 30 years between 1970 versus 2000. So on the JavaScript side I could just cheat and add 30 years. (Just kidding). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So MicroPython on ESP32, I am setting RTC via the ntptime module settime() function, this is a epoch time representation in total seconds? Right? I forward this value via MQTT to the receiving system, which runs JavaScript.
Per the JavaScript documentation I just need to multiple this value to milliseconds, and then use the JavaScript native date object. But this fails to result in an accurate date and time.
For example ESP32 '786249776' should be (UTC) some thing like 11-30-2024 2:44 am or about that. But on Javascript this value converts to about '1994-12-01T02:44:50.000Z' or so, given I am cutting and pasting values while writing this text. The hours, minutes, seconds is right. It is the date that is way off. This is a puzzle? No?
If I don't do anything to the value and just pass it to the JavaScript datetime object, I get this result '1970-01-10T02:24:10.242Z
' which implies the raw value from ESP32 is time only no date information? Yet within MicroPython the date is represented correctly.
Using a common UTC conversion site on the web... this also implies the raw value '786249776' is not a true epoch value...
This illustrates the result in JavaScript, so the question is, what 'magic' is MicroPython doing to allow conversion with date represented? Using say... where theTime is 786249776
The result is 11-30-2024 02:42:56 AM... what? :) Is the date magically encode in a value that seems to be time only?
Beta Was this translation helpful? Give feedback.
All reactions