Utime. Localtime() Timestamp Micropython

I'm trying to get the current timestamp on my Feather Huzzah 32 running micro python. I have read some of the documentation on utime which should be able to get the current timestamp, but I can't seem to figure it out.

When I do utime.localtime() it returns (2000,1,1,0,min,secs,5,1). I'm trying to get the current time, how would I do this?

(Standard python libraries like datetime are not supported)

3

2 Answers

import utime
import machine
print(dir(utime))

set_time = utime.mktime((2020, 1, 27, 19, 37, 0, 0, 27))
print(set_time)
print(utime.localtime(set_time))

print(utime.mktime(utime.localtime()))
print(utime.localtime())
print(utime.localtime(utime.ticks_add(set_time, utime.mktime(utime.localtime()))))

not only do you need to initialise the RTC yo need to set it. On pyboard I use a tuple of the form (Y,M,D,0,h,m,s,0). The micropython epoch begins at 1/1/2000 so your displaying the correct current time 5 milli seconds after reset

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest