문제

string DateCreated = "2012-05-24 12:34:40.060"; USA culture

How do I create the string into a Date time object with a format that include the month, day, year, hour, minutes, seconds, milliseconds. I think the format is this "MM/dd/yyyy hh:mm:ss.fff tt" but not sure. ** ** = underline in red, its an error

I need the datetime object because I want to pass it through another function that only accept a value of "DateTime" and not a string

Any help would be appreciated.

Thank You

this is what I have so far but i know its wrong

  string DateCreated = "2012-05-24 12:34:40.060";
  DateTime dt = **new DateTime(DateCreated);** 
  DateTime dateCreated = **dateCreated.ToString("MM/dd/yyyy hh:mm:ss.fff tt")**;
도움이 되었습니까?

해결책

var dateTime = DateTime.ParseExact(DateCreated, "yyyy-MM-dd HH:mm:ss.fff");

다른 팁

string dateCreated = "2012-05-24 12:34:40.060";
DateTime myDate = DateTime.ParseExact(dateCreated, "yyyy-MM-dd HH:mm:ss.fff",
                                       System.Globalization.CultureInfo.InvariantCulture)

you can also use

Convert.ToDateTime Method (String)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top