String to DateTime
//String to DateTimeString MyString; MyString="1999-09-01 21:34 PM"; //MyString = "1999-09-01 21:34 p.m."; //Depends on your regional settingsDateTime Mydatetime; Mydatetime=NewDateTime (); Mydatetime= DateTime.ParseExact (MyString,"yyyy-mm-dd hh:mm TT", NULL);
DateTime to String
// DateTime to String New DateTime (1999)= mydatetime.tostring ( " yyyy-mm-dd hh:mm TT ");
Format String for Dates
Your format is string
Your most important key. In the most of my projects, I make it a constant and then refer to the constant value in my code.
The following is the most commonly used format characters:
D-Numeric Day of the month without a leading zero.dd-Numeric Day of the month with a leading zero.ddd-abbreviated name of the day of the WEEK.DDDD-Full name of the day of the week.f,ff,fff,ffff,fffff,ffffff,fffffff-fraction of a second. the more Fs the higher the Precision.h- AHour Clock, no leading zero.hh- AHour clock with leading zero. H- -Hour Clock, no leading zero. HH- -Hour clock with leading ZERO.M-Minutes with no leading zero.mm-Minutes with leading zero. M-Numeric Month with no leading zero. MM-Numeric Month with a leading zero. MMM-abbreviated name of month. MMMM-Full month NAME.S-Seconds with no leading ZERO.SS-Seconds with leading zero.t-am/PM but only the first letter . TT-AM/PM (a.m./p.m.) Y-Year with outcentury and leading zero.yy-Year with outcentury, with leading zero.yyyy-Year with Century.zz-Time zone offSetWith +/-.
Excerpt from: Http://www.codeproject.com/Articles/14743/Easy-String-to-DateTime-DateTime-to-String-and-For
Easy String to DateTime, datetime to String and formatting