Mr. Muh
Mr. Muh

Reputation: 649

MVC, JsonResult, DateTime and the Timezone

Good Day my fellow programmers,

I now have spent 2 days looking for a solution, and are about to go crazy..

That's the Problem:

What i have done: Client-side: Store Time Info in UTC Format [so a dateobjet.toUTCString() gives me the correct date i want to have, just before postig to the controller]

So is there a way to tell the JsonResult-Converter to just ignore the Timezone-Info and use the UTC-Time?

Thanks,

Mr.Muh

OK, i hope to describe it in a better (and shorter):

So, How can i get the correct UTC time stored to my C# DateTime ?

Thanks :)

Upvotes: 4

Views: 2876

Answers (1)

Nathan A
Nathan A

Reputation: 11339

If I understand you correctly, you want to ignore the timezone. You can "reset" your DateTime object to UTC (without affecting the actual value) using DateTime.SpecifyKind:

DateTime utcTime = DateTime.SpecifyKind(originalDateTime, DateTimeKind.Utc);

Upvotes: 2

Related Questions