I will try my best to explain what is happening now.

I have an MVC application running from an IST time. (UTC +05:30)

In the DB (MySQL) I have date in the format 2013-10-10 00:00:00

And before sending to the View, I am converting it into a string as

dt.ToShortDateString()

so that I get only 2013-10-10

However when I am in timezone (UTC) Dublin, it returns the date '9' instead of '10'.

I used following code to serialize to JSON format. Please let me know how can I get the date same as in DB, without timezone issues.

var newSerializedDates = '@Html.Raw(new JavaScriptSerializer().Serialize(Model.SelectedDate))';

And then to the browser format :

 var newSerializedDates = '@Html.Raw(new JavaScriptSerializer().Serialize(Model.SelectedDate))';

if (newSerializedDates != 'null') {
var jsonDates = JSON.parse(serializedDates);

var selectArrayFromDB = [];

for (var i = 0; i < jsonDates.length; i++) {
var dateSelectedFormat = new Date(parseInt(jsonDates[i].substr(6)));
}
有帮助吗?

解决方案

We should parse the Date Format into a required format before sending it to the function. That is instead of sending DateTime, it will be better to change to a desired forma and then send it to the said function. That solved my issue.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top