在格鲁吉亚(基督教)日期转换为波斯日期,反之亦然

时间:2015-04-15 15:35:14

标签: python date datetime

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

All I found是一些小工具和东西,它们将创建波斯日历。我不想要波斯日历。我只想将日期转换为彼此。 那我怎么能这样做呢?

4 个答案:

答案 0 :(得分:11)

在网上挖掘更多内容后,我发现a library that somebody wrote for this purpose: Jalali.py

您可以使用此Python代码将Gregorian和Persian日期相互转换。

>>> import jalali
>>> jalali.Persian('1393-1-11').gregorian_string()
'2014-3-31'
>>> jalali.Persian(1393, 1, 11).gregorian_datetime()
datetime.date(2014, 3, 31)
>>> jalali.Persian('1393/1/11').gregorian_string("{}/{}/{}")
'2014/3/31'
>>> jalali.Persian((1393, 1, 11)).gregorian_tuple()
(2014, 3, 31)

>>> jalali.Gregorian('2014-3-31').persian_string()
'1393-1-11'
>>> jalali.Gregorian('2014,03,31').persian_tuple()
(1393, 1, 11)
>>> jalali.Gregorian(2014, 3, 31).persian_string("{0}")
'1393'

答案 1 :(得分:3)

此外,您可以使用<a href="<?php echo get_page_link(130); ?>">Accreditations</a> 库,如下所示:

jdatetime

the document中详细了解其他功能。

答案 2 :(得分:1)

您可以使用PersianTools库:

示例:

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

>>> JalaliDate.today()
JalaliDate(1398, 3, 5, Yekshanbeh)

>>> JalaliDate.today().to_gregorian()
datetime.date(2019, 5, 26)

>>> JalaliDate.to_jalali(2013, 9, 16)
JalaliDate(1392, 6, 25, Doshanbeh)

>>> JalaliDate(datetime.date(1990, 9, 23)) 
JalaliDate(1369, 7, 01, Yekshanbeh)

>>> JalaliDateTime.now().to_gregorian()
datetime.datetime(2016, 7, 8, 1, 43, 24, 720505)

答案 3 :(得分:1)

pip install jdatetime

import jdatetime 
fa_date = jdatetime.date.today()
fa_date.j_months_fa[0]
jdatetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")#'Tue, 05 Far 1399 15:49:44'
jdatetime.datetime.now().strftime("%y %m %d") #'99 01 05'
jdatetime.datetime.now().strftime("%Y %m %d") # '1399 01 05'

jdatetime.datetime.now().strftime('%A %B')


 import jdatetime
 jalili_date = jdatetime.date(1399,1,5).togregorian()
 gregorian_date =  jdatetime.date.fromgregorian(day=24 ,month=3,year=2020)