export function dateToDatetimeLocal(date: Date): string { function ten(i: number) { return (i < 10 ? '0' : '') + i; } const YYYY = date.getFullYear(); const MM = ten(date.getMonth() + 1); const DD = ten(date.getDate()); const HH = ten(date.getHours()); const II = ten(date.getMinutes()); const SS = ten(date.getSeconds()); return YYYY + '-' + MM + '-' + DD + 'T' + HH + ':' + II + ':' + SS; } export const dateToIsoString = (function (BST) { // BST should not be present as UTC time if (new Date(BST).toISOString().slice(0, 16) === BST) { return (date: Date): string => { return new Date(date.getTime() + date.getTimezoneOffset() * 60000) .toISOString(); }; } else { return (date: Date) => date.toISOString(); } }('2006-06-06T06:06'));