Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir/s,

Good day.

I'm having a hard time on finding conversion of this date string to date time
in vb.net mvc 5
Here's my sample string date:

Fri Jul 11 00:00:00 UTC+0800 2014


I would like to convert this string to datetime value

I made this solution but still I'm getting this error:

String was not recognized as a valid DateTime.


Here's my existing code in vb.net

C#
'Dim datestring As [String] = "Fri Jul 11 00:00:00 UTC+0800 2014"
                   Dim datestring As [String] = descriptor.Value.ToString
                   Dim d = datestring.Split(New Char() {" "c}, 5).Take(4)
                   Dim dt As DateTime = DateTime.Parse(d.Aggregate(Function(x, y) x + " " + y))
                   descriptor.Value = dt





I hope someone could help me. Thank you in advance...
Posted

1 solution

Try using DateTime.TryParseExact:
VB
Dim [date] As String = "Fri Jul 11 00:00:00 UTC+0800 2014"
Dim dat As DateTime
If DateTime.TryParseExact([date], "ddd MMM dd HH:mm:ss 'UTC'zzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, dat) Then
    Console.WriteLine(dat)
End If
By "stringifying" the UTC indicator and adding the "zzz" UTC-plus-offset code it shoudl do what you want.
 
Share this answer
 
Comments
Silver Lightning 24-Jul-14 5:14am    
It works, please accept my highest gratitude to you...
OriginalGriff 24-Jul-14 5:49am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900