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

前端 未结 5 1963
梦谈多话
梦谈多话 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:09

    var arabicDate = "١٩٩٤-٠٤-١١";
    var europeanDate = arabicDate.replace(/[\u0660-\u0669]/g, function(m) {
      return String.fromCharCode(m.charCodeAt(m) - 0x660 + 0x30);
    }).split('-').reverse().join('-');
    console.log(europeanDate);
    // => 11-04-1994
    

    EDIT: Derp. Python, not JavaScript. I'll leave it here for someone to rewrite.

提交回复
热议问题