I'm trying to convert the following string to a DateTimeOffset
二 5月 16 14:41:40 +0800 2023
which translates to "Tue May 16 14:41:40 +0800 2023"
I have tried the following code:
DateTimeOffset.Parse(lastLogin, new CultureInfo("zh-CN"), DateTimeStyles.None)
But unfortunately without success.
I have also tried ParseExact() with the following formats: ddd MMM d HH:mm:ss zzz yyyy and d MMM d HH:mm:ss zzz yyyy. Also without success.
System.FormatException: 'The string '二 5月 16 14:43:10 +0800 2023' was not recognized as a valid DateTime. There is an unknown word starting at index '0'.'
The default zh-CN culture has the abbreviated day names as the following array:
So you could create your own
DateTimeFormatInfoobject you can use to parse the string. You can use the zh-CN culture as the starting point:You need to clone the starting point because the starting point is a readonly object that will give an error if you try to change it.