You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
431 B

4 years ago
  1. <script lang="ts">
  2. export let time: Date | string = new Date();
  3. let timeStr = "";
  4. function formatTime(time: Date): string {
  5. const pad = (n:number) => n < 10 ? '0'+n : n.toString();
  6. return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}   ${pad(time.getHours())}:${pad(time.getMinutes())}`
  7. }
  8. $: timeStr = formatTime(new Date(time));
  9. </script>
  10. <span>{timeStr}</span>
  11. <style></style>