idontusefolioscope
idontusefolioscope

Reputation: 29

How can I convert string dates with arabic characters to english string dates? preferably by using DateTime

This is an example Arabic date: (٢٠٢٢-٠٦-٠٤T٠٥:١٠:٠٢+03:00) when I try to convert it from iso format to a regular readable date it gives this error

date = '٢٠٢٢-٠٦-٠٤T٠٥:١٠:٠٢+03:00'
date = datetime.datetime.fromisoformat(date)
ValueError: Invalid isoformat string: '٢٠٢٢-٠٦-٠٤T٠٥:١٠:٠٢+03:00'

I need to translate Arabic numbers into regular numbers in order for this to work, I have tested google translating this date to english and it worked so it is possible. I couldn't find a way to do this using datetime.

Upvotes: 0

Views: 505

Answers (1)

Ahmad
Ahmad

Reputation: 349

You can use Unidecode library:

from unidecode import unidecode
date = '٢٠٢٢-٠٦-٠٤T٠٥:١٠:٠٢+03:00'
date = datetime.datetime.fromisoformat(unidecode(date))

Upvotes: 5

Related Questions