FormatDate.ets 561 B

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