I have in my jquery scripts, an object containing dates received from an Ajax call, returned in milliseconds, as "Date(380415600000)". These dates are saved in UTC on the database, but some of these are DateTime, some are just Date, because representing data as Birthday, Date of validity start of a document. Now, when these data are converted by the existing jquery code, all these dates are localized, even the birthdays or the validity start, but this have no sense, because in this case the only relevant information is the date. The method that convert these dates from milliseconds is the following
function dotnetDateToJSDate(dotnetDate) {
var re = /^\/Date\((-?\d+)\)\/$/,
m = re.exec(dotnetDate);
if (m && m.length > 1)
return new Date(parseInt(m[1]));
else return dotnetDate;
}
and the new Date()
applies the current timezone, so, if a birthday date is for example, 01/06/1980, depending on the current timezone, is converted, for example, as 31/05/1980 because of the time offset of the current timezone. Is there a way to convert these dates from milliseconds without applying the localization, if they are only dates? Thanks
I somehow went to a solution, I did
return moment.utc(parseInt(m[1]));
passing te date in milliseconds, and then I formatted it with
momentDate.format(actualOptions.shortFormat);
But if the date is not in the Daylight Saving Time period, dates converted are always in the day before, as, for example, 20/01/1980 23:00:00. Is there a way to check this, and add one hour? If I check the date with the isDST()
function, is it acceptable?
Instead if the DST is applied, the resulting time is 22:00