Reputation: 649
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:
On The WebPage, the User modifies an object, and i need to store the time without timezone info. [ i just care about hours and minutes ]
the object is postet to the Server [ asp.net mvc 5] via ajax as a JsonResult.
Let's say, Server has Timezone UTC + 1 , User selects 09:00 on the webpage, json is ajax't to my controller, and boom - the resulting Object in my mvc controller has a DateTime Object with a time of 10:00 ;
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):
ClientSite: JavaScript date with the time i need in UTC (but still with some timezone information, which i don't need), let's say e.g. 'Fri, 01 Feb 1980 09:00:00 GMT' as a result from .toUTCString()
Get's wrapped up together with other variables in some Json & posted via ajax to my asp.net mvc 5 controller
ServerSide: Controller has my C# - Class as Argument (so automatically converting Json-Object to C# - Class), but the resulting DateTime part now says 10:00:00 due to my server TimeZone set to UTC+1.
So, How can i get the correct UTC time stored to my C# DateTime ?
Thanks :)
Upvotes: 4
Views: 2876
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