我正在使用google日历api来创建日历上的事件。我遵循谷歌的api文件在这里 https:/developers.google.comcalendarcreate-events#javascript。.
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'attendees': [
{'email': '[email protected]'},
{'email': '[email protected]'}
],
};
我的支持服务目前正以以下格式返回事件开始日期和时间。2020-06-10T10:00:00.000
和字符串中的持续时间 '01:30:00'
. 它也返回我的时区 America/Los_Angeles
. 我怎么可能设置我的开始日期时间和结束日期时间使用这些值。
样品:
var timeString = "2020-06-10T10:00:00.000";
var timeZone = "America/Los_Angeles";
var duration = '01:30:00';
var startDate = new Date(timeString);
var msDuration = (Number(duration.split(':')[0]) * 60 * 60 + Number(duration.split(':')[1]) * 60 + Number(duration.split(':')[2])) * 1000;
var endDate = new Date(startDate.getTime() + msDuration);
var isoStartDate = new Date(startDate.getTime()-new Date().getTimezoneOffset()*60*1000).toISOString().split(".")[0];
var isoEndDate = new Date(endDate.getTime()-(new Date().getTimezoneOffset())*60*1000).toISOString().split(".")[0];
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': isoStartDate,
'timeZone': timeZone
},
'end': {
'dateTime': isoEndDate,
'timeZone': timeZone
},
'attendees': [
{'email': '[email protected]'},
{'email': '[email protected]'}
],
}