0

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?

2
  • is it a json return from any service or method?? Commented Oct 17, 2013 at 4:24
  • 2
    Are those supposed to be newline characters with backslashes? And please show exactly what you have for string b. Have you tried anything? Commented Oct 17, 2013 at 4:28

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

The cleanest way is probably to use DateTime.TryParse() with a custom IFormatProvider, or you can use DateTime.TryParseExact().

http://msdn.microsoft.com/en-us/library/9h21f14e.aspx

1 Comment

More likely, DateTime.TryParseExact

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.