There is only a .toISOString() method , but it will not use the local time zone. To do this, you need to format the string yourself:
function toLocaleISOString(date) { function pad(n) { return ("0"+n).substr(-2); } var day = [date.getFullYear(), pad(date.getMonth()+1), pad(date.getDate())].join("-"), time = [date.getHours(), date.getMinutes(), date.getSeconds()].map(pad).join(":"); if (date.getMilliseconds()) time += "."+date.getMilliseconds(); var o = date.getTimezoneOffset(), h = Math.floor(Math.abs(o)/60), m = Math.abs(o) % 60, o = o==0 ? "Z" : (o<0 ? "+" : "-") + pad(h) + ":" + pad(m); return day+"T"+time+o; }
Bergi Feb 18 '13 at 17:38 2013-02-18 17:38
source share