1
0
silverbullet/plug-api/lib/dates.ts

19 lines
414 B
TypeScript
Raw Normal View History

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