<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>