[英]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.