Home

Awesome

ustrftime

A MicroPython implementation of time.strftime

About

ustrftime.strftime accepts a formatting string and a time.localtime() 8-tuple (whose MicroPython format is described here).

Usage

>>> from ustrftime import strftime
>>> import time
>>> strftime('%c', time.localtime())
Mon Jul 31 14:42:14 2023
>>> strftime('%X', time.localtime())
14:42:34
>>> strftime('%x', time.localtime())
31/07/23

Notes

A specific locale can be achieved by editing the ustrftime.strftime function as well as the __DOTW, __MOTY, __DATE_TIME_FMTDIR, __DATE_FMTDIR, __TIME_FMTDIR variables.

The following formatting directives are supported (full list here):

DirectiveMeaning
%aLocale’s abbreviated weekday name.
%ALocale’s full weekday name.
%bLocale’s abbreviated month name.
%BLocale’s full month name.
%cLocale’s appropriate date and time representation.
%dDay of the month as a decimal number [01,31].
%HHour (24-hour clock) as a decimal number [00,23].
%IHour (12-hour clock) as a decimal number [01,12].
%jDay of the year as a decimal number [001,366].
%mMonth as a decimal number [01,12].
%MMinute as a decimal number [00,59].
%pLocale’s equivalent of either AM or PM.
%SSecond as a decimal number [00,61].
%UWeek number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
%wWeekday as a decimal number [0(Sunday),6].
%WWeek number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
%xLocale’s appropriate date representation.
%XLocale’s appropriate time representation.
%yYear without century as a decimal number [00,99].
%YYear with century as a decimal number.
%%A literal '%' character.