c# - How can I parse an Arabic Umm Al-Qura date string into a .NET DateTime object? -


i have following arabic date in umm al-qura calendar want parse .net datetime object:

الأربعاء‏، 17‏ ذو الحجة‏، 1436

this date equivalent september 30th 2015 in gregorian calendar.

i've been trying following "standard" c# code parse date, without success:

var cultureinfo = new cultureinfo("ar-sa"); cultureinfo.datetimeformat.calendar = new umalquracalendar(); // default 1 anyway  var dateformat = "dddd، dd mmmm، yyyy"; //note ، instead of ,  var datestring = "‏الأربعاء‏، 17‏ ذو الحجة‏، 1436"; datetime date; datetime.tryparseexact(datestring, dateformat, cultureinfo.datetimeformat, datetimestyles.allowwhitespaces, out date); 

no matter do, result of tryparseexact false. how parse string in .net?

by way, if start datetime object, can create exact date string above using tostring()'s overloads on datetime without problems. can't other way around apparently.

your datestring 30 characters long , contains 4 unicode 8207 u+200f right left mark characters, dateformat not.

// gives string 26 characters long var str = new datetime(2015,9,30).tostring(dateformat, cultureinfo.datetimeformat) 

right left mark not whitespace.

if contains rlm/lrm/alm should strip them out. same isolates lri/rli/fsi , pdi sets, , lre/rle sets. may not want lro though. lro used legacy data rtl characters stored in opposite order, i.e. in left-to-right order. in these cases may want reverse characters.

parsing dates random places hard problem. need layered solution, try first 1 method, in priority order until succeed. there no 100% solution though, because people can type like.

see here more information: http://www.unicode.org/reports/tr9/


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -