useFormatDate.ts 584 B

1234567891011121314151617
  1. export function useFormatDate(){
  2. const formatDate = (date:string) => {
  3. const d = new Date(date);
  4. const year = d.getFullYear();
  5. const month = String(d.getMonth() + 1).padStart(2, '0');
  6. const day = String(d.getDate()).padStart(2, '0');
  7. const hours = String(d.getHours()).padStart(2, '0');
  8. const minutes = String(d.getMinutes()).padStart(2, '0');
  9. const seconds = String(d.getSeconds()).padStart(2, '0');
  10. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  11. };
  12. return {
  13. formatDate,
  14. };
  15. }