In 2022 the create Google calendar event link looks like this:
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?
const formatDate = (date) => {
???
};
const myDate = new Date();
const myFormattedDate = formatDate(myDate);
console.log(myFormattedDate)
expecting output:
20220418T013000Z
Any nice looking and easy solution (rather than getHours(),getMinutes()
,etc.)?
JS Dates have an inbuilt.toISOString() method which gets the right format, then just remove special characters:
let date = new Date();
let isoDate = date.toISOString()
let formattedDate = isoDate.replace(/[^\w\s]/gi, '');
console.log(formattedDate)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.