0

I'm trying to generate links to Google calendar and see this tool:

https://decomaan.github.io/google-calendar-link-generator/

And the links are generated as:

https://www.google.com/calendar/render?action=TEMPLATE&text=Appointment+with+VULKOVICH%2C+BILL&details=a+Description&location=a+Location&dates=20210105T103300Z%2F20210114T103300Z

and as you can see the dates are like:

20210105T103300Z

and I am trying to convert this to my own dates but I don't know which type is this and how to format. I have the dates both, in moment or in date, but don't know how to convert.

Sudhanshu Kumar
  • 1,926
  • 1
  • 9
  • 21
Ulises 2010
  • 478
  • 1
  • 6
  • 16
  • So what have you tried? Format is `YYYYMMDDTHHIISS00Z` – Justinas Jan 11 '21 at 11:53
  • 2
    This is ISO 8601 – ElmoVanKielmo Jan 11 '21 at 11:54
  • I try convert to ISO8601 but try moment().toISOString() or new Date().toISOString() return '2021-01-11T12:28:18.435Z' what is not exactly '20210111T122800Z' what I expected and don't works :-( – Ulises 2010 Jan 11 '21 at 12:33
  • Since you're using moment.js: `moment().utc().format('YYYYMMDDTHHmmss[Z]')`, or without a library `new Date().toISOString().replace(/\W/g,'').replace(/\d{3}Z/,'Z')`. This is really a duplicate of [*How to format a JavaScript date*](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date). – RobG Jan 11 '21 at 12:58
  • Thanks a lot....@RobG this works for me!!!! If you answer me I mark your solution as ok... if you can't I will write by myselt to help for someone looking for the same!!! Thanks again!! – Ulises 2010 Jan 11 '21 at 15:22

2 Answers2

0

That's ISO-8601

The first part is the date in year-month-date order, the second part is the time and the final letter indicates the timezone (here Z for 'Zulu')

Johan
  • 477
  • 4
  • 8
  • Thanks a lot, but if I try moment().toISOString() or new Date().toISOString(); both return '2021-01-11T12:28:18.435Z' what is not exactly '20210111T122800Z' what I expected and don't works :-( – Ulises 2010 Jan 11 '21 at 12:32
0

Since you're using moment.js: moment().utc().format('YYYYMMDDTHHmmss[Z]'), or without a library new Date().toISOString().replace(/\W/g,'').replace(/\d{3}Z/,'Z'). This is really a duplicate of How to format a JavaScript date.

Source: comment by RobG Jan 11 at 12:58

RobC
  • 22,977
  • 20
  • 73
  • 80
Ulises 2010
  • 478
  • 1
  • 6
  • 16