Currently working on the Google Calendar API and basically my end will provide Start and End date for user to pick the date and time. But would like anyone to advise how to convert them from (DatePicker/TimePicker/input field) to RFC 3339 format (e.g. 2013-07-24T10:00:00.000-07:00).

有帮助吗?

解决方案

var date = new Date();
var timeZone = date.getTimezoneOffset();
alert(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + "T" + date.getHours() + ":" + date.getMinutes()  + ":" + date.getSeconds() + "." + date.getMilliseconds() + (timeZone > 0 ? "-" : "+") + Math.floor(Math.abs(timeZone) / 60) + ":" + Math.abs(timeZone) % 60);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top