Dapper
Dapper

Reputation: 69

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.

https://docs.micropython.org/en/latest/library/utime.html

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)

Upvotes: 1

Views: 3489

Answers (2)

PrimeTime
PrimeTime

Reputation: 189

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()))))

Upvotes: 3

phil
phil

Reputation: 565

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

Upvotes: 1

Related Questions