time.ts 495 B

1234567891011
  1. export const formatter = (timestamp: string | null) => {
  2. if (!timestamp) return '';
  3. const date = new Date(timestamp);
  4. const year = date.getFullYear();
  5. const month = `0${date.getMonth() + 1}`.substr(-2, 2);
  6. const day = `0${date.getDate()}`.substr(-2, 2);
  7. const hour = `0${date.getHours()}`.substr(-2, 2);
  8. const minute = `0${date.getMinutes()}`.substr(-2, 2);
  9. const second = `0${date.getSeconds()}`.substr(-2, 2);
  10. return `${year}/${month}/${day} ${hour}:${minute}:${second}`;
  11. };