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

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

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

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

5条回答
  •  走了就别回头了
    2021-01-23 07:07

    I have made a solution to this problem. May be not a best but its working :)

    # -*- coding: utf8 -*-
    import unicodedata
    s = u"١٩٩٤-٠٤-١١"
    
    def date_conv(unicode_arabic_date):
        new_date = ''
        for d in unicode_arabic_date:
            if d != '-':
                new_date+=str(unicodedata.decimal(d))
            else:
                new_date+='-'
        return new_date
    
    print date_conv(s)
    

    1994-04-11

提交回复
热议问题