Globalization

Posted: July 27, 2010 in C#, Globalization
Tags: ,

Saving date for specific culture …

System.IFormatProvider format = new System.Globalization.CultureInfo(“en-US”, true);
DateTime dt = DateTime.Parse(“Sun Feb 01 00:03:43 2009”, format);

or

DateTime dt = DateTime.ParseExact(“Fri Aug 01 09:03:43 2003”, “ddd MMM dd HH:mm:ss yyyy”, new System.Globalization.CultureInfo(“en-US”, true));

DateTime.Parse(“Sun Feb 01 00:03:43 2009”) will parse the date string based on the current user culture which will fail the conversion for some clutures. So it is good to save date with some specific culture.

ParseExact – parses to specified format.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s