简体   繁体   English

如何获取添加到日历谷歌链接的日期格式

[英]How can i get date format for add to calender google link

I want to generate a google calendar joining link through javascript function.我想通过 javascript function 生成一个谷歌日历加入链接。 For this i need a specific date format that google calendar understands.为此,我需要谷歌日历可以理解的特定日期格式。 eg Below is the google calendar link例如下面是谷歌日历链接

https://calendar.google.com/calendar/u/0/r/eventedit?dates=20201210T093000Z/20201210T103000Z&text=Test+Test&location&details=&sf=true https://calendar.google.com/calendar/u/0/r/eventedit?dates=20201210T093000Z/20201210T103000Z&text=Test+Test&location&details=&sf=true

In this link the date format required is somewhat like this 20201210T093000Z.在此链接中,所需的日期格式有点像 20201210T093000Z。 This is the start date for the event and after / is the end date of the event.这是活动的开始日期,之后 / 是活动的结束日期。

Suppose i have a date 12/4/2020(dd/mm/yyyy) and time 4:00pm.假设我的日期是 2020 年 12 月 4 日(日/月/年),时间是下午 4:00。 how can i convert it to above date format.如何将其转换为上述日期格式。

This is a Date object这是一个Date object

This is the MDN Documentation on it.这是关于它的MDN 文档 For example, this snippet will produce a date in the format "20201210T093000Z" (depending on the platform).例如,此代码段将生成格式为“20201210T093000Z”的日期(取决于平台)。

 let now = new Date console.log(now)

So to create a new Date object with your time you could do this:因此,要使用您的时间创建一个新的Date object,您可以这样做:

 let myDate = new Date() myDate.setYear(2020) myDate.setMonth(3) // Note it has to be one less than the actual month myDate.setDate(12) myDate.setHours(16) myDate.setMinutes(0) myDate.setSeconds(0) myDate.setMilliseconds(0) console.log(myDate)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM