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.

formatDateTime.ts 572B

123456789101112131415161718
  1. const formatDate = (isoDate: string) => {
  2. const date = new Date(isoDate);
  3. const day = date.getDate().toString().padStart(2, '0');
  4. const month = date.toLocaleString('default', { month: 'short' }); // e.g., "May"
  5. const year = date.getFullYear();
  6. let hours = date.getHours();
  7. const minutes = date.getMinutes().toString().padStart(2, '0');
  8. const ampm = hours >= 12 ? 'PM' : 'AM';
  9. hours = hours % 12;
  10. hours = hours ? hours : 12; // the hour '0' should be '12'
  11. return `${day} ${month} ${year}, ${hours}:${minutes} ${ampm}`;
  12. };
  13. export default formatDate;