Files
stufflog2/svelte-ui/src/components/DateSpan.svelte
T
2020-12-31 17:49:54 +01:00

17 lines
431 B
Svelte
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
export let time: Date | string = new Date();
let timeStr = "";
function formatTime(time: Date): string {
const pad = (n:number) => n < 10 ? '0'+n : n.toString();
return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}   ${pad(time.getHours())}:${pad(time.getMinutes())}`
}
$: timeStr = formatTime(new Date(time));
</script>
<span>{timeStr}</span>
<style></style>