silverbullet/lib/dates.ts

19 lines
414 B
TypeScript
Raw Normal View History

2022-04-12 02:34:09 +08:00
export function niceDate(d: Date): string {
2022-10-07 06:04:12 +08:00
function pad(n: number) {
let s = String(n);
if (s.length === 1) {
2022-10-12 17:47:13 +08:00
s = "0" + s;
2022-10-07 06:04:12 +08:00
}
return s;
}
2022-10-12 17:47:13 +08:00
return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
2022-04-12 02:34:09 +08:00
}
export function niceTime(d: Date): string {
const isoDate = d.toISOString();
let [date, time] = isoDate.split("T");
// hh:mm:ss
return time.split(".")[0];
}