C # .net convert yyyyMMdd date to system.datetime.?

Possible duplicate:
how to convert date from yyyyMMdd format to mm-dd-yyyy fomrat

I have a string that contains a date in yyyyMMdd format. I want to convert this date to system date format. using the ConvertTo.DateTime () method or any other simple method.

string vlaue = 19851231 // yyyyMMdd

DateTime dateTime = 1985/12/31;

+44
c # datetime
Jan 18 '11 at 4:23
source share
2 answers
string time = "19851231"; DateTime theTime= DateTime.ParseExact(time, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); 
+121
Jan 18 '11 at 4:27
source share

look at the static methods DateTime.Parse() and DateTime.TryParse() . They allow you to pass a date string and a format string and return a DateTime object.

http://msdn.microsoft.com/en-us/library/6fw7727c.aspx

+1
Jan 18 '11 at 4:26
source share



All Articles