Resolved What is wrong with the following DateTime.ParseExact?

zhuanyi

New member
Joined
Mar 15, 2010
Messages
3
Programming Experience
1-3
Hi,

I have a text string like this which I will need to parse:

FriMar1200:00:00EST2010

And I used the following code:

VB.NET:
Date.ParseExact("FriMar1200:00:00EST2010", "dddMMMddHH:mm:sszzzyyyy", Nothing)

And it is giving me a A first chance exception of type 'System.FormatException' occurred in mscorlib.dll error.

Please help!

Thanks!
 
Last edited:
The problem is with the time zone abbreviation. You need to replace that with an offset time.

VB.NET:
        Dim theDate As String = "FriMar1200:00:00EST2010"
        Dim format As String = "dddMMMddHH:mm:sszzzyyyy"
        Dim provider As CultureInfo = CultureInfo.InvariantCulture
        Dim result As DateTime
        DateTime.TryParseExact(theDate.Replace("EST", "+11:00"), format, provider, DateTimeStyles.None, result)

Edit: Looks like you found the solution while I was typing up the example.

Here's a list of time zone abbreviations and their offsets to help you out in any case. Time zone abbreviations
 

Latest posts

Back
Top