Python Date Conversion. How to convert arabic date string into date or datetime object python

前端 未结 5 1954
梦谈多话
梦谈多话 2021-01-23 06:40

I have to convert this date into normal date string/object.

١٩٩٤-٠٤-١١ to 11-04-1994.

5条回答
  •  囚心锁ツ
    2021-01-23 06:55

    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"١٩٩٤-٠٤-١١")
    

提交回复
热议问题