How to convert US date time to UK datetime and vice versa?

Posted by Poster under C# category on | Views : 20608
Sometimes when a user is entering the DateTime value in the US format (MM/dd/YYYY) and your server is in UK that only support UK format (dd/MM/yyyy), you may get error while parsing the DateTime value. Below code snippet is the solution for that.

DateTime ukDateTimeFormat = DateTime.Parse("10/26/2009 06:47", System.Globalization.CultureInfo.GetCultureInfo("en-us"));

To reverse ie from UK format to US format, use following code snippet

DateTime usDateTimeFormat = DateTime.Parse("26/10/2009 06:47", System.Globalization.CultureInfo.GetCultureInfo("en-gb"));


Comments or Responses

Login to post response