Files
timetracker/games/static/js/utils.js
Lukáš Kucharczyk 4ea6466f1e
All checks were successful
continuous-integration/drone/push Build is passing
input datetime-local needs day to also be two digits
2023-03-02 21:25:25 +01:00

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())
}`;
}