How can I convert "2011-09-30T00:00:00" date time string to UTC date in JavaScript?
I tried new Date("2011-09-30T00:00:00") but it converts to "2011-09-29T23:00:00.000Z".
Simple:
function createDateUTC(dateUTC) {
return new Date(dateUTC + "Z");
}
var dateUTC = createDateUTC("2011-09-30T00:00:00");
console.log(dateUTC);
new Date("2011-09-30T00:00:00")should not convert it to"2011-09-29T23:00:00.000Z", that happens only if you donew Date("2011-09-30T00:00:00").toISOString(). Where are you trying this? Have you triednew Date("2011-09-30T00:00:00").toUTCString()?