jQuery UI DatePicker日期转换为RFC 3339格式

jQuery UI DatePicker日期转换为RFC 3339格式

问题描述:

目前在Google Calendar API上工作,基本上我的结束将为用户提供开始和结束日期来选择日期和时间。但愿任何人建议如何将它们从(DatePicker / TimePicker / input field)转换为RFC 3339格式(例如2013-07-24T10:00:00.000-07:00)。

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);