Replies: 1 comment 1 reply
-
You can determine the epoch with tests like if gmtime(0)[0] == 2000: Time and date calculations are usually best done in seconds since the epoch. Conversion between epochs is accomplished by adding a constant. The easy way to determine the constant is in CPython: >>> from datetime import date
>>> (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
3155673600
>>> (date(2000, 1, 1) - date(1970, 1, 1)).days * 24*60*60
946684800
>>> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
"Some" micropython ports use a different epoch that starts in 2000, rather than 1970.
The difference is defined in
micropython/lib/shared/timeutils/timeutils.h
and set to eitherTIMEUTILS_SECONDS_1970_TO_2000
or0
, depending on the port.Question: is it possible to get at this number from micropython code?
Sending the output from
time.mktime(time.gmtime(0))
to a (unix-like) host and for comparisonwhere
(2000, 1, 1, 0, 0, 0, 5, 1, -1)
is the output fromtime.mktime(time.gmtime(0))
run on micropython (augmented by -1 as needed e.g. on the esp32) does the trick, but is convoluted. Hence the question for a simpler solution, preferably all contained within micropython.Beta Was this translation helpful? Give feedback.
All reactions