0

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)

Zoran Pandovski
  • 2,312
  • 14
  • 24
Dapper
  • 59
  • 3
  • 12
  • Have you [initialised the RTC](https://docs.micropython.org/en/latest/library/machine.RTC.html)? Also see `utime`'s [known issues](https://docs.micropython.org/en/latest/esp8266/general.html#known-issues) on the ESP8266 port. – nekomatic Nov 16 '18 at 15:18
  • Yes, I have initialized the RTC :( – Dapper Nov 16 '18 at 16:18
  • I would try asking on the forum at micropython.org. – nekomatic Nov 19 '18 at 09:40

2 Answers2

2
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()))))
PrimeTime
  • 121
  • 1
  • 6
1

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

phil
  • 561
  • 3
  • 10