datetime and strftime

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Posts: 3
Joined: Sun Mar 12, 2017 1:27 am

datetime and strftime

Postby icenov » Sun Mar 12, 2017 1:35 am

Just started with micropython and the forum and looking to log some voltages through the X19 port of PYBv1.1 board running 1.8.7 release.
I have used sync_rtc to set the board time, but I'd like to use the time to make the filename unique, like - DD_MM_HH_logfile.dat
I've used datetime strftime on (big) python to write this string, but can't find the datetime and strftime on micropython.

Can anyone suggest a way forward? Thanks

User avatar
Posts: 1382
Joined: Fri Jul 18, 2014 8:01 am

Re: datetime and strftime

Postby pythoncoder » Mon Mar 13, 2017 9:06 am


Code: Select all

import pyb
rtc = pyb.RTC()
t = rtc.datetime()
name = '{:02d}_{:02d}_{:02d}_logfile.dat'.format(t[2], t[4], t[5])

Arguably the name would be more unique (if there are degrees of uniqueness ;) ) if you included year and month information.
Peter Hinch

Return to “General Discussion and Questions”

Who is online

Users browsing this forum: No registered users and 1 guest