You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
589 B
JavaScript

export function toLocalISO(date) {
const tzo = -date.getTimezoneOffset()
const dif = tzo >= 0 ? '+' : '-'
const pad = function (num) {
return num.toString().padStart(2, '0')
}
return (
date.getFullYear() +
'-' +
pad(date.getMonth() + 1) +
'-' +
pad(date.getDate()) +
'T' +
pad(date.getHours()) +
':' +
pad(date.getMinutes()) +
':' +
pad(date.getSeconds()) +
dif +
pad(Math.floor(Math.abs(tzo) / 60)) +
':' +
pad(Math.abs(tzo) % 60)
)
}