【发布时间】:2021-06-30 10:45:52
【问题描述】:
我可以使用这个指向谷歌日历的链接来创建一个活动。 但我认为时间即将到来(比我想要的活动时间提前 5.30 小时)
示例: This link 将创建一个事件,但它显示的时间是从中午 12.30 到下午 4 点。 这个活动应该是早上 6.30 到 10 点。
According to this link,从时间字符串中删除 Z 应该在事件中设置用户的本地时间。
使用用户的时区:20201231T193000/20201231T223000(不指定时区);
要使用 UTC 时区,请将 datetime 转换为 UTC,然后使用 Z 后缀:20201231T193000Z/20201231T223000Z;
我也尝试了this link 的相同解决方案,但活动时间仍未到来。它在链接中被转换。
const startDateTimeFormattedGoogle = eventStartDateTime ? eventStartDateTime.format(
"YYYYMMDDTHHmmss"
) : null;
const endDateTimeFormattedGoogle = eventEndDateTime ? eventEndDateTime.format(
"YYYYMMDDTHHmmss"
) : null;
const addToGoogleLink = `https://calendar.google.com/calendar/render?action=TEMPLATE&dates=${startDateTimeFormattedGoogle}/${endDateTimeFormattedGoogle}&location=${data.location}&text=${data.title}`;
更新:
console.log(88888, moment(eventStartDateTime).format('YYYYMMDDTHHmmssZ'),
result: 88888 20210430T123000+00:00 20210430T160000+00:00
console.log(111111, moment(eventStartDateTime).format('YYYYMMDDTHHmmss'),
moment(eventEndDateTime).format('YYYYMMDDTHHmmss'))
result : 111111 20210430T123000 20210430T160000
result url: https://calendar.google.com/calendar/render?action=TEMPLATE&dates=20210430T123000+00:00/20210430T160000+00:00&location=Calgary, Downtown&text=The 2020 Festival
【问题讨论】:
-
哦,我明白了,这是否意味着如果我提供 Z,它将转换为用户的时区?我说对了吗?
-
不确定这是怎么回事。我添加了 Z 并将其删除。我用最新发现更新了这个问题。无论时区如何,我的节点 js 服务器上的时间都会打印相同的时间。客户端机器上的最终网址也始终显示相同的时间。
标签: javascript timezone momentjs google-calendar-api