Format directives¶
strftime and strptime are implemented in pure Python with the same
directive set on every platform. Unknown directives raise ValueError (the
standard library passes them to the C library, which varies by platform).
Directives¶
Directive |
Meaning |
Example ( |
|---|---|---|
|
Abbreviated weekday |
|
|
Full weekday |
|
|
Abbreviated BS month |
|
|
Full BS month |
|
|
Century |
|
|
Day of the month (01–32) |
|
|
Day of the month, space-padded |
|
|
Microsecond (000000–999999) |
|
|
BS week-numbering year (see |
|
|
Hour (00–23) |
|
|
Hour (01–12) |
|
|
Day of the BS year (001–366) |
|
|
BS month (01–12) |
|
|
Minute |
|
|
AM/PM |
|
|
Second |
|
|
Weekday, Monday = 1 … Sunday = 7 |
|
|
Week of the BS year, weeks starting Sunday (00–53) |
|
|
BS week number (01–53) |
|
|
Weekday, Sunday = 0 … Saturday = 6 |
|
|
Week of the BS year, weeks starting Monday (00–53) |
|
|
Year without century; parsed as 2000 + yy |
|
|
BS year, at least four digits |
|
|
UTC offset |
|
|
UTC offset |
|
|
Time zone name (empty if naive) |
|
|
Locale date and time |
|
|
Locale date |
|
|
Locale time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Newline, tab, |
Devanagari digits: %O¶
%O before any numeric directive (%OY, %Od, %OH, …) renders that field
with Devanagari digits, whatever the locale. This follows the POSIX meaning of
%O (“alternative digits”).
Locales¶
strftime, strptime and the Locale*Calendar classes take an explicit
Locale. The built-in locales are
EN (English names, ASCII digits; the default) and
NE (Devanagari names and digits). The process C locale
is never consulted.
|
|
|
|---|---|---|
Months |
Baishakh, Jestha, Asar, Shrawan, Bhadra, Ashwin, Kartik, Mangsir, Poush, Magh, Falgun, Chaitra |
बैशाख, जेठ, असार, साउन, भदौ, असोज, कात्तिक, मंसिर, पुस, माघ, फागुन, चैत |
Weekdays (Monday first) |
Monday … Sunday |
सोमबार, मङ्गलबार, बुधबार, बिहीबार, शुक्रबार, शनिबार, आइतबार |
|
AM, PM |
पूर्वाह्न, अपराह्न |
|
|
|
|
|
|
Create variants with dataclasses.replace(), for example Nepali names
with ASCII digits:
>>> import dataclasses
>>> from sambat import date
>>> from sambat.locale import NE, ASCII_DIGITS
>>> date(2083, 6, 15).strftime("%d %B %Y", locale=dataclasses.replace(NE, digits=ASCII_DIGITS))
'15 असोज 2083'
Parsing rules¶
Numbers may use ASCII or Devanagari digits.
Month and weekday names are matched case-insensitively against the locale’s names and its documented alternative spellings (
Locale.month_aliases,Locale.weekday_aliases).%ymeans 2000 + yy.Without a year the result is in BS 2000; parsing a day of the month without a year emits
DeprecationWarning, as Python 3.13+ does.Composite directives (
%c,%x,%X,%D,%F,%r,%R,%T) expand to their templates.