尼泊尔枣API
nepali-date的Python项目详细描述
尼泊尔日期(Bikram Sambat B.S)API
类似于datetime.date()的api,它在bs日期而不是ad上工作。
安装
您可以从pypi安装尼泊尔日期:pip install nepali-date
如何使用
BS Date today
fromnepali_dateimportNepaliDate# print today BS dateprint(NepaliDate.today())
Creating NepaliDate instance
fromnepali_dateimportNepaliDatemy_birthday=NepaliDate(2051,10,1)# ormy_birthday=NepaliDate('2051','10','1')
Adding/Subtracting datetime.timedelta to NepaliDate instance
importdatetimefromnepali_dateimportNepaliDatemy_birthday=NepaliDate(2051,10,1)hundred_days_after_my_birthday=my_birthday+datetime.timedelta(days=100)hundred_days_before_my_birthday=my_birthday-datetime.timedelta(days=100)
Converting datetime.date to NepaliDate or vice-versa
importdatetimefromnepali_dateimportNepaliDatemy_birthday_in_ad=datetime.date(1995,10,15)my_birthday_in_bs=NepaliDate.to_nepali_date(my_birthday_in_ad)my_birthday=NepaliDate(2051,10,1)my_birthday_in_ad=my_birthday.to_english_date()
月历
Current nepali month calendar
fromnepali_dateimportNepaliDateNepaliDate.calendar()
日期采用isoformat()'yyyy-mm-dd'
dt=NepaliDate(2076,4,2)print(dt.isoformat())# outputs 2076-04-02
日期显示格式
Format Specifier | Meaning | Example |
---|---|---|
^{ | Day of the month as a zero-padded decimal number. | 01, 02, ..., 32 |
^{ | Month as abbreviated name. | Bai, Jes, ..., Cha |
^{ | Month as full name. | Baishak, Jestha, ..., Chait |
^{ | Month as a zero-padded decimal number. | 01, 02, ..., 12 |
^{ | Year without century as a zero-padded decimal number. | 00, 01, ..., 99 |
^{ | Year with century as a decimal number. | 0001, 0002, ..., 2075, 2076, ..., 9999 |
dt=NepaliDate(2076,4,7)print("{0:B} {0:d}".format(dt))# outputs Shrawan 07