feat-git #10
|
@ -3,22 +3,9 @@
|
|||
|
||||
if (typeof date === 'string') date = new Date(date);
|
||||
|
||||
const pad = function (str: string): string {
|
||||
return ('0' + str).slice(-2);
|
||||
};
|
||||
import { format } from "$lib/scripts/formatted_date";
|
||||
|
||||
const year = date.getFullYear().toString();
|
||||
const month = pad((date.getMonth() + 1).toString());
|
||||
const day = pad(date.getDate().toString());
|
||||
const hour = pad(date.getHours().toString());
|
||||
const min = pad(date.getMinutes().toString());
|
||||
const sec = pad(date.getSeconds().toString());
|
||||
const tz = -date.getTimezoneOffset();
|
||||
const sign = tz >= 0 ? '+' : '-';
|
||||
const tzHour = pad((tz / 60).toString());
|
||||
const tzMin = pad((tz % 60).toString());
|
||||
|
||||
let formattedDate = `${year}-${month}-${day}T${hour}:${min}:${sec}${sign}${tzHour}:${tzMin}`;
|
||||
const formattedDate = format(date);
|
||||
</script>
|
||||
|
||||
{formattedDate}
|
||||
|
|
20
src/lib/scripts/formatted_date.ts
Normal file
20
src/lib/scripts/formatted_date.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
export const format = (
|
||||
date: Date
|
||||
) => {
|
||||
const pad = function (str: string): string {
|
||||
return ('0' + str).slice(-2);
|
||||
};
|
||||
|
||||
const year = date.getFullYear().toString();
|
||||
const month = pad((date.getMonth() + 1).toString());
|
||||
const day = pad(date.getDate().toString());
|
||||
const hour = pad(date.getHours().toString());
|
||||
const min = pad(date.getMinutes().toString());
|
||||
const sec = pad(date.getSeconds().toString());
|
||||
const tz = -date.getTimezoneOffset();
|
||||
const sign = tz >= 0 ? '+' : '-';
|
||||
const tzHour = pad((tz / 60).toString());
|
||||
const tzMin = pad((tz % 60).toString());
|
||||
|
||||
return `${year}-${month}-${day}T${hour}:${min}:${sec}${sign}${tzHour}:${tzMin}`;
|
||||
};
|
Loading…
Reference in New Issue
Block a user