0
string date = "2017-01-05T00:00:00+00:00";
string time = Convert.ToDateTime(date).ToString("MM/dd/yyyy");

I am getting the above date from my client database, i am trying to convert that time to string but when i executed it was returning 01/04/2017 . why this is converting one day before ?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
Trinadh Velchuri
  • 179
  • 1
  • 11
  • 3
    This could be time zone related. It looks like you have a +00:00 at the end. This usually signifies time zone offsets. So if your not in the same timezone the default Format provider may give you the time relative to where you are. look at http://stackoverflow.com/questions/19402049/convert-datetime-without-timezone – Hack Jan 09 '17 at 16:22
  • It worked for me, Thank you @Hack – Trinadh Velchuri Jan 09 '17 at 19:52

1 Answers1

0

Ok my bad. Here goes:

Yes I agree its a timezone offset issue, but this will work anyways:

string date = "2017-01-05T00:00:00+00:00";
string time = DateTimeOffset.Parse(date).DateTime.ToString("MM/dd/yyyy");
dadde
  • 649
  • 1
  • 11
  • 24