简体   繁体   English

如何在 Javascript 2022 中创建 Google 日历链接日期?

[英]How to create Google calendar link date in Javascript 2022?

In 2022 the create Google calendar event link looks like this: 2022 年创建 Google 日历活动链接如下所示:

https://calendar.google.com/calendar/u/0/r/eventedit?sf=true&output=xml&text=sometext&location=somelocation&details=somedetails&dates=20220418T013000Z/20220416T020000Z

How do you formate such date in Javascript?你如何在 Javascript 中形成这样的日期?

const formatDate = (date) => {
 ???
};
const myDate = new Date();
const myFormattedDate = formatDate(myDate);
console.log(myFormattedDate)

expecting output:期待 output:

20220418T013000Z

Any nice looking and easy solution (rather than getHours(),getMinutes() ,etc.)?任何好看和简单的解决方案(而不是getHours(),getMinutes()等)?

JS Dates have an inbuilt.toISOString() method which gets the right format, then just remove special characters: JS Dates 有一个 inbuilt.toISOString() 方法可以获取正确的格式,然后只需删除特殊字符:

  let date = new Date();
  let isoDate = date.toISOString()
  let formattedDate = isoDate.replace(/[^\w\s]/gi, '');

  console.log(formattedDate)

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

相关问题 如何创建一个Javascript日期过滤器作为滑块(而不是日历)? - How to create a Javascript date filter as slider (not calendar)? 如何在 javascript 中通过谷歌日历 api 获得谷歌见面链接? - How to get Google meet link thru google calendar api in javascript? 如何为用户创建一个订阅我的Google日历的链接 - How to create a link for user to subscribe my Google Calendar 如何在GAS中转换和传递日期以在Google日历中创建事件? - How to convert and pass the date in GAS to create an event in Google calendar? 如何创建“订阅日历”链接到适用于Android上Google日历的ics文件? - How to create a “Subscribe to Calendar” link to an ics file that works on Google Calendar on Android? 在javascript / jquery中添加链接中不带//的Google日历 - In javascript/ jquery adding a google calendar without // in the link 使用 javascript 使用谷歌日历检查日期和时间 - Check date and time with google calendar using javascript 如何使用Javascript / jQuery / D3.js创建iCal / Google日历之类的日历 - How to create a calendar like iCal/Google Calendar using Javascript/jQuery/D3.js 日历中的今天日期链接 - Today date link in calendar 如何通过JavaScript设置rich:calendar日期? - How to set rich:calendar Date via JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM