FormatDate.ets 469 B

12345678910
  1. export function formatDate(date: Date): string {
  2. const year = date.getFullYear();
  3. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  4. const day = date.getDate().toString().padStart(2, '0');
  5. const hours = date.getHours().toString().padStart(2, '0');
  6. const minutes = date.getMinutes().toString().padStart(2, '0');
  7. const seconds = date.getSeconds().toString().padStart(2, '0');
  8. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  9. }