Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.format()

Format a NepaliDate instance into a custom string using token patterns for English and Nepali output.

The format method transforms a NepaliDate instance into a formatted string according to a pattern of token specifiers. It supports tokens for year, month, day, weekday, hours, minutes, and seconds, with full support for localized English names as well as Devanagari script numerals and words.


Import

from nepali_date_library import NepaliDate

Signature

def format(self, format_str: str) -> str:

Common Format Tokens

TokenOutput FormatExample
YYYYFour digit year2081
YYTwo digit year81
MMMMFull month nameKartik
MMMShort month nameKar
MMTwo digit month number07
MOne or two digit month number7
DDTwo digit day of month15
DOne or two digit day of month15
ddddFull weekday nameFriday
dddShort weekday nameFri
HHTwo digit 24-hour time14
mmTwo digit minute30
ssTwo digit second45

Examples

from nepali_date_library import NepaliDate

date = NepaliDate("2081-07-15")

# Standard ISO format
print(date.format("YYYY-MM-DD")) # "2081-07-15"

# Long English date
print(date.format("dddd, MMMM DD, YYYY")) # "Friday, Kartik 15, 2081"

Advertisement

On this page