Formatting time for export

I created a calendar in jquery that is exported to ical. However, I have some problems with datetime.

ical export script expects date / time in this format: 19970714T170000Z.

Does anyone know what it is and how should I prepare my line?

thanks

+6
source share
3 answers

Reading the RFC () reference gives:

3.3.5. Date-time

[...]

date-time = date "T" time

The value type "DATE-TIME" expresses time values ​​in three forms:

FORM No. 1: DATE WITH LOCAL TIME For example, the following January 18, 1998 at 11:00: 19980118T230000

FORM No. 2: DATE WITH TIME UTC CAPITAL LETTER Z suffix, time value.
For example, the following January 19, 1998, at 07:00 UTC: 19980119T070000Z

FORM No. 3: LOCAL DATE AND ZONE TIME TZID = America / Triathlon: 19980119T020000

DTSTART: 19970714T133000; Local Time DTSTART: 19970714T173000Z; UTC DTSTART time; TZID = America / Triathlon: 19970714T133000; Local time and time; zone link

+9
source

To answer the question about converting to this format in jQuery, you can do the following.

var n = d.toISOString(); 
0
source

It is almost like toISOString

 function formatDateTime(date) { const year = date.getUTCFullYear(); const month = pad(date.getUTCMonth() + 1); const day = pad(date.getUTCDate()); const hour = pad(date.getUTCHours()); const minute = pad(date.getUTCMinutes()); const second = pad(date.getUTCSeconds()); return `${year}${month}${day}T${hour}${minute}${second}Z`; } function pad(i) { return i < 10 ? `0${i}` : `${i}`; } // Example: const date = new Date('2017-05-31T11:46:54.216Z'); date.toISOString() // '2017-05-31T11:46:54.216Z' date.toJSON() // '2017-05-31T11:46:54.216Z' formatDateTime(date) // '20170531T114654Z' 
-1
source

Source: https://habr.com/ru/post/915295/


All Articles