IT Community - Software Programming, Web Development and Technical Support

How to convert a date to a globally accepted date format, in DOT NET 2005?

This is a discussion on How to convert a date to a globally accepted date format, in DOT NET 2005? within the C# Programming forums, part of the Software Development category; How to convert a date to a globally accepted date format, in DOT NET 2005?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-25-2007, 02:20 AM
Archer Archer is offline
D-Web Programmer
 
Join Date: Jun 2007
Posts: 52
Archer is on a distinguished road
Question How to convert a date to a globally accepted date format, in DOT NET 2005?

How to convert a date to a globally accepted date format, in DOT NET 2005?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date format yymmdd itbarota HTML, CSS and Javascript Coding Techniques 2 03-03-2008 08:07 PM
Convert a date in milliseconds back to a date string itbarota HTML, CSS and Javascript Coding Techniques 2 03-03-2008 08:03 PM
Validate a date to be in the format dd/mm/yyyy itbarota HTML, CSS and Javascript Coding Techniques 1 02-25-2008 08:21 PM
How can I show the documents last modified date in the format: month, date, year, tim Pvinothkumar HTML, CSS and Javascript Coding Techniques 3 12-28-2007 04:58 AM
How do I format the Last-Modified date with javascript? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 10-12-2007 10:17 PM


All times are GMT -7. The time now is 03:20 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0