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 NepaliDateSignature
def format(self, format_str: str) -> str:Common Format Tokens
| Token | Output Format | Example |
|---|---|---|
YYYY | Four digit year | 2081 |
YY | Two digit year | 81 |
MMMM | Full month name | Kartik |
MMM | Short month name | Kar |
MM | Two digit month number | 07 |
M | One or two digit month number | 7 |
DD | Two digit day of month | 15 |
D | One or two digit day of month | 15 |
dddd | Full weekday name | Friday |
ddd | Short weekday name | Fri |
HH | Two digit 24-hour time | 14 |
mm | Two digit minute | 30 |
ss | Two digit second | 45 |
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"Related
date.clone(): Duplicate a date instance.NepaliDate.get_month_name(): Static month name helper.
Advertisement
date.current_quarter()
Return the standard Bikram Sambat calendar quarter number from one to four for the current date.
date.clone()
Create an independent deep clone of an existing NepaliDate instance.