String parsing and formatting directives - FObersteiner/zdt GitHub Wiki

string parsing, string generation

Available (βœ”), planned (o) and not-planned (-) directives as of zdt v0.3.5:

directive parse format example meaning (see also: technical notes)
%d βœ” βœ” 01, 02, …, 31 Day of the month as a zero-padded decimal number.
%e βœ” (%d) βœ” 1, 2, …, 31 Day of the month as a space-padded decimal number.
%a (βœ”) βœ” Sun, Mon, …, Sat (en_US); So, Mo, …, Sa (de_DE) Weekday as locale’s abbreviated name. (1)
%:a βœ” βœ” Sun, Mon, …, Sat English name of weekday, abbreviated.
%A (βœ”) βœ” Sunday, Monday, …, Saturday (en_US); Sonntag, Montag, …, Samstag (de_DE) Weekday as locale’s full name. (1)
%:A βœ” βœ” Sunday, Monday, …, Saturday English name of weekday.
%m βœ” βœ” 01, 02, …, 12 Month as a zero-padded decimal number.
%b (βœ”) βœ” Jan, Feb, …, Dec (en_US); Jan, Feb, …, Dez (de_DE) Month as locale’s abbreviated name.
%:b βœ” βœ” Jan, Feb, …, Dec Month as English abbreviated name.
%B (βœ”) βœ” January, February, …, December (en_US); Januar, Februar, …, Dezember (de_DE) Month as locale’s full name.
%:B βœ” βœ” January, February, …, December Month as English full name.
%Y βœ” βœ” 0001, 0002, …, 2013, 2014, …, 9998, 9999 Year with century as a decimal number.
%y βœ” βœ” 00, 01, …, 99 Year without century as a zero-padded decimal number (year%100). Assumes the current century.
%C - βœ” 00, 01, …, 99 Century as a zero-padded 2-digit number (year/100)
%G o βœ” 0001, 0002, …, 2013, 2014, …, 9998, 9999 ISO 8601 year with century representing the year that contains the greater part of the ISO week (%V).
%H βœ” βœ” 00, 01, …, 23 Hour (24-hour clock) as a zero-padded decimal number.
%k βœ” (%H) βœ” 1, …, 23 Hour (24-hour clock) as a space-padded decimal number.
%I βœ” βœ” 01, 02, …, 12 Hour (12-hour clock) as a zero-padded decimal number.
%P βœ” (%p) βœ” AM, PM am or pm identifier, upper-case
%p βœ” βœ” am, pm am or pm identifier, lower-case
%M βœ” βœ” 00, 01, …, 59 Minute as a zero-padded decimal number.
%S βœ” βœ” 00, 01, …, 60 Second as a zero-padded decimal number.
%f βœ” βœ” 000000000, 000000001, …, 999999999 Fractional seconds with nanosecond precision, zero-padded to 9 digits.
%:f βœ” (%f) βœ” 999 Fractional seconds with millisecond precision, zero-padded to 3 digits.
%::f βœ” (%f) βœ” 999999 Fractional seconds with microsecond precision, zero-padded to 6 digits.
%z βœ” βœ” +0000 UTC offset in the form (+
%:z βœ” (%z) βœ” +10:30 see β€˜z’
%::z βœ” (%z) βœ” -03:07:12 see β€˜z’
%:::z βœ” (%z) βœ” +01 see β€˜z’
%Z - βœ” (empty), EST, Z Time zone abbreviation. Naive datetime gives empty string.
%:Z - βœ” (empty), EST, UTC Displays UTC as β€˜UTC’ instead of β€˜Z’, otherwise behaves like %Z.
%i - βœ” Europe/Berlin, Asia/Kolkata IANA time zone identifier. Gives empty string if not defined for given datetime.
%j βœ” βœ” 001, 002, …, 366 Day of the year as a zero-padded decimal number.
%w o βœ” 0, 1, …, 6 Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.
%u o βœ” 1, 2, …, 7 ISO 8601 weekday as a decimal number where 1 is Monday.
%W o βœ” 00, 01, …, 53 Week number of the year (Monday as the first day of the week) as a zero-padded decimal number. All days in a new year preceding the first Monday are considered to be in week 0.
%U o βœ” 00, 01, …, 53 Week number of the year (Sunday as the first day of the week) as a zero-padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.
%V o βœ” 01, 02, …, 53 ISO 8601 week as a decimal number with Monday as the first day of the week. Week 01 is the week containing Jan 4.
%T βœ” βœ” 2022-08-01T12:24:19.008993841+02:00 ISO 8601 date and time with optional fractional seconds (if not zero) and UTC offset (if time zone / UTC offset defined)
%t βœ” βœ” 2022-W07-4 ISO calendar format.
%c - o Tue Aug 16 21:30:00 1988 (en_US); Di 16 Aug 21:30:00 1988 (de_DE) Locale’s appropriate date and time representation.
%x - o 08/16/88 (None); 08/16/1988 (en_US); 16.08.1988 (de_DE) Locale’s appropriate date representation.
%X - o 21:30:00 (en_US); 21:30:00 (de_DE) Locale’s appropriate time representation.
%% βœ” βœ” % A literal '%' character.

Technical notes

(1) Parsing: if a day name is supplied together with a date, the day name is not validated against that date.