The bootstrap timepicker is passing data that looks like this:
"Mon Jan 01 0001 17:00:02 GMT-0456 (Eastern Standard Time)
"
When passed to the api, the string is cast to the C# datetime type except that the time is changed from 5pm to another time due to the GMT-0456 time zone data in the string. Here is after saving to the database: "0001-01-03 09:56:10.0000000" How can I ensure that the time remains the same as the user inputs in the UI (5PM)?
2
Answers
The solution was to take given datetime, convert it to a string, parse out the time from that string, create a new date using the hours and minutes retrieved from prior, and then format that newly created date into ISO 8601 format. Then pass this new date into the api instead of the one that is created by the timepicker.
Store UTC dates on the database that will solve your issue so that every value of date in the database is in UTC time.
This has the additional advantage that anyone in the world can use your application.
Converting Local Time to UTC – SO Answer