I have an MVC5 Web Application as web interface for my time recording app. My android app sends its times as string to server, there I parse them to .NET DateTime and store it in Database. When I load the time records again and create a JavaScript array I get one additional hour added. I already tried a lot but this post seems to solve the problem: stackoverflow
new Date(date.valueOf() + date.getTimezoneOffset() * 60000);
My question is: Is this the correct way to do? I don’t need any culture or time zones for time recording. A time record that starts at 6 am and ends at 6pm has always this values. Actually it even MUST have this values! Isn’t there a way to tell the JavaScript Date that it should do nothing with my time? Just hold the value I set to it?
UPDATE/Extension: My web inteterface is a MVC5 application and the communication with android phones is done with a WCF service. To make the the code I posted above run I kicked out the JavaScriptSerializer and wrote the JSON array with StringBuilder. This gave me the possibility to include the snipped posted above and let it be executed on the client. I also tried all DateTime.Kind's (local, unspecified and UTC) in combination with the JavascriptSerializer but with no success.
Again, I need unmodified datetimes on client side.
With the answer of Matt I now see three options:
- My code posted above
- Parsing the DateTime and append a Z for GMT
- Add SerializerSettings.DateTimeZoneHandling in Global.ascx Application_Start.
Cheers, Stefan