Convert.Todatetime returns the previous day

Asked

Viewed 86 times

2

Using C#, when I run it:

Convert.ToDateTime("Wed, 20 May 2015 01:36:39 +0000")

He returns it to me:

{19/05/2015 22:36:39}
    Date: {19/05/2015 00:00:00}

How does it return the correct value?

1 answer

1


It seems that the Convert.ToDateTime is converting the original date into UTC for a local date.

Checks whether the property Kind is equal to DateTimeKind.Local.

If it is, you have to convert the date to UTC again

date = date.ToUniversalTime();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.