Hopefully the title says it all but either way I'll clarify. I rarely work with Javascript dates so this has me stumped.
So I'm pulling dates through via MVC and I'm pushing that into a Javascript array, each time I push into the array I create a new Date()
with Year, Month and Day. But every time I read those values it adds a month!
Code snippet:
//Get list of dates
var auditDates = [];
@foreach (var a in Model.Audits)
{
//Push into auditDates Array
@:auditDates.push(new Date('@a.AuditDate.Year', '@a.AuditDate.Month', '@a.AuditDate.Day'));
//Write Actual dates stored in audits to console without pushing into auditDates Array
@:console.log("Actual Date: " + '@a.AuditDate.Year' + " " + '@a.AuditDate.Month' + " " + '@a.AuditDate.Day');
}
//Write to console with array full of dates
console.log(auditDates);
As you can see from the console the first block is the Actual date stored in the model - just for visual indicators.
The second block is the incorrect dates, it's outputting December which in fact should be November!
The third block is just all the dates I'm going to compare against. At this point there is no real relevance to the question.
So if anyone could point in the direction of fixing the incorrect dates issue, it will be very much appreciated.
Regards,