Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

formatting time for ical export

const date = "July 1, 2022";
const time = "1:30 PM";

function calendarTimeFormat(date) {
    const year = Intl.DateTimeFormat('en', { year: 'numeric', timeZone: 'utc' }).format(date);
    const month = Intl.DateTimeFormat('en', { month: '2-digit', timeZone: 'utc' }).format(date);
    const day = Intl.DateTimeFormat('en', { day: '2-digit', timeZone: 'utc' }).format(date);
    const hour = Intl.DateTimeFormat('en', { hour: '2-digit', timeZone: 'utc', hour12: false }).format(date).split(' ')[0];
    const minute = Intl.DateTimeFormat('en', { minute: '2-digit', timeZone: 'utc' }).format(date).split(' ')[0];
    return year + month + day + "T" + hour + minute + "00Z";
}

const d = Date.parse(`${date} ${time}`);
console.log(calendarTimeFormat(d);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #formatting #time #ical #export
ADD COMMENT
Topic
Name
4+4 =