Monorepo containing core modules of Zeichen.
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.

17 lines
568 B

  1. type FormatDate = (d: Date) => string
  2. export const formatDate: FormatDate = d => {
  3. const yearRaw = d.getFullYear()
  4. const monthRaw = d.getMonth() + 1
  5. const dateRaw = d.getDate()
  6. const hourRaw = d.getHours()
  7. const minuteRaw = d.getMinutes()
  8. const year = yearRaw.toString().padStart(4, '0')
  9. const month = monthRaw.toString().padStart(2, '0')
  10. const date = dateRaw.toString().padStart(2, '0')
  11. const hour = hourRaw.toString().padStart(2, '0')
  12. const minute = minuteRaw.toString().padStart(2, '0')
  13. return `${year}-${month}-${date} ${hour}:${minute}`
  14. }