View Single Post
  #2  
Old 07-25-2007, 02:21 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Default Re: How to convert a date to a globally accepted date format, in DOT NET 2005?

string myDateTimeValue = "2/16/1992 12:15:12";
DateTime myDateTime = DateTime.Parse (myDateTimeValue); Console.WriteLine ("1) myDateTime = {0}", myDateTime);


// Reverse month and day to conform to a different culture.
// the date is February 16, 1992, 12 hours, 15 minutes and 12 seconds.

IFormatProvider culture = new CultureInfo ("fr-FR", true);
string myDateTimeFrenchValue = " 16/02/1992 12:15:12";
DateTime myDateTimeFrench = DateTime.Parse myDateTimeFrenchValue, culture, DateTimeStyles.NoCurrentDateDefault);
Console.WriteLine ("2) myDateTimeFrench = {0}",myDateTimeFrench);

// the date is February 16, 1992, 12 hours, 15 minutes and 12 seconds.

string[] expectedFormats = {"G", "g", "f" ,"F"};
myDateTimeFrench = DateTime.ParseExact (myDateTimeFrenchValue, expectedFormats, culture, DateTimeStyles.AllowWhiteSpaces); Console.WriteLine ("3) myDateTimeFrench = {0}", myDateTimeFrench);

This example yields the following results:
1) myDateTime = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
Reply With Quote