18 lines
463 B
JavaScript
18 lines
463 B
JavaScript
/**
|
|
* @description Formats Date to a UTC string accepted by the datetime-local input field.
|
|
* @param {Date} date
|
|
* @returns {string}
|
|
*/
|
|
export function toISOUTCString(date) {
|
|
function stringAndPad(number) {
|
|
return number.toString().padStart(2, 0);
|
|
}
|
|
return `${
|
|
date.getFullYear()}-
|
|
${stringAndPad(date.getMonth() + 1)}-
|
|
${stringAndPad(date.getDate())}T
|
|
${stringAndPad(date.getHours())}:
|
|
${stringAndPad(date.getMinutes())
|
|
}`;
|
|
}
|