Javascript 创建一个链接,将事件添加到yahoo calandar
我正在生成一个链接,将事件添加到yahoo日历中。我正在关注这一点。 我的剧本是这样的Javascript 创建一个链接,将事件添加到yahoo calandar,javascript,yahoo,Javascript,Yahoo,我正在生成一个链接,将事件添加到yahoo日历中。我正在关注这一点。 我的剧本是这样的 var MS_IN_MINUTES = 60 * 1000; var formatTime = function (date) { return date.toISOString().replace(/-|:|\.\d+/g, ''); }; var calculateEndTime = function (event) { return event.end ?
var MS_IN_MINUTES = 60 * 1000;
var formatTime = function (date) {
return date.toISOString().replace(/-|:|\.\d+/g, '');
};
var calculateEndTime = function (event) {
return event.end ?
formatTime(event.end) :
formatTime(new Date(event.start.getTime() + (event.duration * MS_IN_MINUTES)));
};
var yHDuration = (Number(Duration.split(':')[0]) * 60 + Number(Duration.split(':')[1]));
var event = {
title: 'Get on the front page of HN', // Event title
start: new Date(MeetingTime), // Event start date
duration: yHDuration, // Event duration (IN MINUTES)
// If an end time is set, this will take precedence over duration
address: 'The internet',
description: 'Get on the front page of HN, then prepare for world domination.',
}
var eventDuration = event.end ?
((event.end.getTime() - event.start.getTime()) / MS_IN_MINUTES) :event.duration;
// Yahoo dates are crazy, we need to convert the duration from minutes to hh:mm
var yahooHourDuration = eventDuration < 600 ?
'0' + Math.floor((eventDuration / 60)) :
Math.floor((eventDuration / 60)) + '';
var yahooMinuteDuration = eventDuration % 60 < 10 ?
'0' + eventDuration % 60 :
eventDuration % 60 + '';
var yahooEventDuration = yahooHourDuration + yahooMinuteDuration;
// Remove timezone from event time
var st = formatTime(new Date(event.start - (event.start.getTimezoneOffset() *
MS_IN_MINUTES))) || '';
var href = encodeURI([
'http://calendar.yahoo.com/?v=60&view=d&type=20',
'&title=' + (event.title || ''),
'&st=' + '20200611225200',
'&dur=' + (yahooEventDuration || ''),
'&desc=' + (event.description || ''),
'&in_loc=' + (event.address || ''),
'&invitees=' + (InviteesArr || ''),
].join(''));
var link = '<a class="icon-yahoo" target="_blank" href="' +
href + '">Yahoo! Calendar</a>';
console.log(link);
参数并使用时区。我认为您需要的是这个,因为您正在将字符串传递给
&st=
查询参数,而变量st
中已经存储了正确的开始日期:
var href = encodeURI([
'http://calendar.yahoo.com/?v=60&view=d&type=20',
'&title=' + (event.title || ''),
'&st=' + (st || ''),
'&dur=' + (yahooEventDuration || ''),
'&desc=' + (event.description || ''),
'&in_loc=' + (event.address || ''),
'&invitees=' + (InviteesArr || ''),
].join(''));
并回答您关于st
的问题。如果您查看这篇文章,它会说该方法返回从当前区域设置(主机系统设置)到UTC的时区差(以分钟为单位)
如果将返回的分钟数与
getTimeOffset()相乘,然后检查此后减法的第二个答案
毫秒存储在MS\u in\u MINUTES
对于所有用户来说,您的日期在全球范围内正常工作是必要的。试试20200612110600
@Viney我应该在哪里使用它?我的意思是像'&st='+'20200612110600',
@Viney它仍然是一样的
var href = encodeURI([
'http://calendar.yahoo.com/?v=60&view=d&type=20',
'&title=' + (event.title || ''),
'&st=' + (st || ''),
'&dur=' + (yahooEventDuration || ''),
'&desc=' + (event.description || ''),
'&in_loc=' + (event.address || ''),
'&invitees=' + (InviteesArr || ''),
].join(''));