I get two string. string a and string b.
string a="\n 17 Oct \n \n 2013";
string b=//I get UTC time in string format
I need to convert this to "2013-10-17 00-00-00.000" in datetime format. How do I achive this?
I get two string. string a and string b.
string a="\n 17 Oct \n \n 2013";
string b=//I get UTC time in string format
I need to convert this to "2013-10-17 00-00-00.000" in datetime format. How do I achive this?
I think the first example makes no problem when you remove the /n from the string
string a = "\n 17 Oct \n \n 2013";
string b = a.Replace("\n", "");
DateTime D = DateTime.Parse(b);
I am not sure if I used the correct string for the second one. This one comes from the world clock website http://www.worldtimeserver.com/current_time_in_UTC.aspx
string utc = " 4:37 AM \n Thursday, October 17, 2013";
string b1 = utc.Replace("\n", "");
DateTime DateUtc = DateTime.Parse(b1);
Both seem to get parsed as expected.
The cleanest way is probably to use DateTime.TryParse() with a custom IFormatProvider, or you can use DateTime.TryParseExact().
DateTime.TryParseExact