Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# parse GMT date string to DateTime

I'm using http://www.eyecon.ro/bootstrap-datepicker/ plugin to select date, and after date is selected I get e.g. Fri Nov 01 2013 00:00:00 GMT+0100

1) Why am I getting that date format if I set up the plugin with format yyyy-mm-dd ?

2) How to parse Fri Nov 01 2013 00:00:00 GMT+0100 to DataTime with format yyyy-mm-dd ?

like image 711
Tony Avatar asked Nov 09 '13 17:11

Tony


1 Answers

You can use "ddd MMM dd yyyy HH:mm:ss 'GMT'K" format with DateTime.ParseExact like;

string s = "Fri Nov 01 2013 00:00:00 GMT+0100";
DateTime dt = DateTime.ParseExact(s, "ddd MMM dd yyyy HH:mm:ss 'GMT'K", CultureInfo.InvariantCulture);
Console.WriteLine(dt);

Output will be;

10/31/2013 11:00:00 PM

Here a demonstration.

For more informations, take a look at;

  • Custom Date and Time Format Strings
like image 60
Soner Gönül Avatar answered Sep 30 '22 02:09

Soner Gönül