Google API 开始和结束时间格式问题 Node.JS
Google API start and end time format issue Node.JS
我在使用包含在 Node.js 中创建 Google 日历事件数据的变量时遇到问题。我为此尝试了许多不同的时间格式,但收到了奇怪的错误。我尝试声明一个与有效变量相同的变量,但我仍然遇到错误。
//These variables work
const eventStartTime = new Date();
eventStartTime.setDate(eventStartTime.getDay() + 2);
const eventEndTime = new Date();
eventEndTime.setDate(eventEndTime.getDay() + 2);
eventEndTime.setMinutes(eventEndTime.getMinutes() + 45);
//These variables give a 'Bad Request Error', although they are identical to the previous 2 variables when console.logged
let eventStart = calendarLesson.date + " " + calendarLesson.startTime + ":00 GMT+0100 (Central European Standard Time)";
let eventEnd = calendarLesson.date + " " + calendarLesson.endTime + ":00 GMT+0100 (Central European Standard Time)";
//I also tried setting a start and end time variable eg. let testTime= "2020-07-12T09:30:00.0z", which did not give any issues in the query execution
const event = {
summary: 'Lesson',
location: "Classroom",
description: "This is a lesson",
start: {
dateTime: eventStart,
timeZone: 'CET'
},
end: {
dateTime: eventEnd,
timeZone: 'CET'
},
attendee:[{
'email': calendarEmailAddress
}],
reminders: {
//reminder
},
}
第一组变量 console.log:2021 年 1 月 21 日星期四 12:00:00 GMT+0100(欧洲中部标准时间)变量 console.log:2021 年 1 月 21 日星期四 12:00:00 GMT +0100(中欧标准时间)
第二组变量我也尝试设置开始和结束时间变量,例如。 “2020-07-12T09:30:00.0z”,在查询执行中没有出现任何问题,但并不理想,因为我需要使用变量来设置时间。非常感谢您的帮助,因为我已经被这个小但烦人的错误困扰了几个小时。
基于 ,以下是接受的日期和日期时间格式:
日期:
日期,格式为"yyyy-mm-dd"
日期时间:
时间,作为组合的日期时间值(根据 RFC3339 格式化)。除非在 timeZone 中明确指定时区,否则需要时区偏移量。
Example Internet date/time format:
1985-04-12T23:20:50.52Z
1996-12-19T16:39:57-08:00
请删除日期时间字符串中的 " (Central European Standard Time)"
。我在在线 javascript 编译器上尝试了 运行 你的代码片段,但我收到了不同的输出。
我在使用包含在 Node.js 中创建 Google 日历事件数据的变量时遇到问题。我为此尝试了许多不同的时间格式,但收到了奇怪的错误。我尝试声明一个与有效变量相同的变量,但我仍然遇到错误。
//These variables work
const eventStartTime = new Date();
eventStartTime.setDate(eventStartTime.getDay() + 2);
const eventEndTime = new Date();
eventEndTime.setDate(eventEndTime.getDay() + 2);
eventEndTime.setMinutes(eventEndTime.getMinutes() + 45);
//These variables give a 'Bad Request Error', although they are identical to the previous 2 variables when console.logged
let eventStart = calendarLesson.date + " " + calendarLesson.startTime + ":00 GMT+0100 (Central European Standard Time)";
let eventEnd = calendarLesson.date + " " + calendarLesson.endTime + ":00 GMT+0100 (Central European Standard Time)";
//I also tried setting a start and end time variable eg. let testTime= "2020-07-12T09:30:00.0z", which did not give any issues in the query execution
const event = {
summary: 'Lesson',
location: "Classroom",
description: "This is a lesson",
start: {
dateTime: eventStart,
timeZone: 'CET'
},
end: {
dateTime: eventEnd,
timeZone: 'CET'
},
attendee:[{
'email': calendarEmailAddress
}],
reminders: {
//reminder
},
}
第一组变量 console.log:2021 年 1 月 21 日星期四 12:00:00 GMT+0100(欧洲中部标准时间)变量 console.log:2021 年 1 月 21 日星期四 12:00:00 GMT +0100(中欧标准时间)
第二组变量我也尝试设置开始和结束时间变量,例如。 “2020-07-12T09:30:00.0z”,在查询执行中没有出现任何问题,但并不理想,因为我需要使用变量来设置时间。非常感谢您的帮助,因为我已经被这个小但烦人的错误困扰了几个小时。
基于
日期:
日期,格式为"yyyy-mm-dd"
日期时间:
时间,作为组合的日期时间值(根据 RFC3339 格式化)。除非在 timeZone 中明确指定时区,否则需要时区偏移量。
Example Internet date/time format:
1985-04-12T23:20:50.52Z
1996-12-19T16:39:57-08:00
请删除日期时间字符串中的 " (Central European Standard Time)"
。我在在线 javascript 编译器上尝试了 运行 你的代码片段,但我收到了不同的输出。