Skip to content

InitWithDateTimeFormatString Format Details

Michael Miller edited this page Jul 5, 2023 · 2 revisions

This topic covers the details of the string format used to parse the given date time string for the method InitWithDateTimeFormatString. This string is expected to be PROGMEM, so wrap with F().

The format tokens:

* - ignore until the next char in format
! - ignore until NOT the next char
YY - two digit year, assumes 2000 +
YYYY - four digit year, also assumes 2000+ and will basically ignore the first digit and assume always a 2
M - full month name, arbitrary length until next char
MM - two digit month
MMM - abbreviated month name, 3 chars
DD - two digit day of month
hh - hour
mm - minute
ss - seconds
sssss - seconds with decimal (12.34), the decimal part will be ignored as RtcDateTime does not store sub-seconds values.
z - +hh:mm or Z -
using this will adjust the time to UTC from the time-zone present in the string,
without it, it will ignore the time-zone and return the local
note: + or - must be present before hour/minute time-zone offset in the string.
zzz - time zone abbreviation
using this will adjust the time to UTC from the time-zone present in the string,
without it, it will ignore the time-zone and return the local

Examples:


result.InitWithDateTimeFormatString(
        "*, DD MMM YYYY hh:mm:ss zzz", 
        "Sat, 06 Dec 2009 12:34:56 GMT");

Will set result to {2009,12,6,12,34,56}.


result.InitWithDateTimeFormatString(
        "*, DD MMM YYYY hh:mm:ss zzz", 
        "Sun, 06 Dec 2009 12:34:56 PST");

Will set result to the same {2009,12,6,12,34,56} as it returns a UTC.


result.InitWithDateTimeFormatString(
        "YYYY-MM-DD hh:mmz", 
        "2007-07-16 19:20+01:00");

Will set result to {2007,7,16,18,20,0}.


result.InitWithDateTimeFormatString(
        "YYYY-MM-DDThh:mm:sssssz", 
        "2007-07-16T19:20:30.45-01:00");

Will set result to {2007,7,16,20,20,30} as fractional seconds are discarded.

Clone this wiki locally