将格里高利(基督教)日期转换为波斯语日期,反之亦然

2024-05-14 10:43:36 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Python中将Gregorian date转换为Persian date,反之亦然?

All I found是一些小部件和材料,将创建波斯日历。我不要波斯日历。我只想把日期互相转换。 那我该怎么做呢?


Tags: date部件allgregorian中将材料foundpersian
2条回答

此外,还可以使用jdatetime库,如下所示:

 import jdatetime
 jalili_date = jdatetime.date(1396,2,30).togregorian()
 gregorian_date =  jdatetime.date.fromgregorian(day=19,month=5,year=2017) 

有关其他函数的详细信息,请参见the document

您可以使用PersianTools库:

示例:

>>> from persiantools.jdatetime import JalaliDate
>>> import datetime

>>> JalaliDate.today()
JalaliDate(1395, 4, 18, Jomeh)

>>> JalaliDate(datetime.date(1990, 9, 23))  # Gregorian to Jalali
JalaliDate(1369, 7, 1, Yekshanbeh)

>>> JalaliDate.to_jalali(2013, 9, 16)       # Gregorian to Jalali
JalaliDate(1392, 6, 25, Doshanbeh)

>>> JalaliDate(1392, 6, 25).to_gregorian()  # Jalali to Gregorian
datetime.date(2013, 9, 16)

>>> JalaliDate.fromtimestamp(578707200)     # Timestamp to Jalali
JalaliDate(1367, 2, 14, Chaharshanbeh)

相关问题 更多 >

    热门问题