Python 日期转换.如何将阿拉伯语日期字符串转换为日期或日期时间对象python [英] Python Date Conversion. How to convert arabic date string into date or datetime object python
本文介绍了Python 日期转换.如何将阿拉伯语日期字符串转换为日期或日期时间对象python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须将此日期转换为正常的日期字符串/对象.
I have to convert this date into normal date string/object.
١٩٩٤-٠٤-١١ 至 11-04-1994.
١٩٩٤-٠٤-١١ to 11-04-1994.
推荐答案
这里是我写的解决方案:
Here is a method I wrote to solve it:
def arab_to_decimal(timestamp):
if not isinstance(timestamp, unicode) return
table = {1632: 48, # 0
1633: 49, # 1
1634: 50, # 2
1635: 51, # 3
1636: 52, # 4
1637: 53, # 5
1638: 54, # 6
1639: 55, # 7
1640: 56, # 8
1641: 57} # 9
return timestamp.translate(table)
arab_to_decimal(u"١٩٩٤-٠٤-١١")
这篇关于Python 日期转换.如何将阿拉伯语日期字符串转换为日期或日期时间对象python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文