Skip to content

Commit

Permalink
Merge pull request #277 from rocketfren/r/fix-date-formats
Browse files Browse the repository at this point in the history
fix: use Intl.DateTimeFormat for timestamps
  • Loading branch information
0xIchigo authored Jan 23, 2024
2 parents 04b1824 + 4d53da2 commit f4026fb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib/util/format-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export default (timestamp: number) => {
? new Date(timestamp * 1000)
: new Date(timestamp);

const dateString = `${date.getMonth() + 1}/${date.getDate()}/${String(
date.getFullYear()
).slice(-2)}`;

const timeString = date.toLocaleTimeString();

return `${timeString.slice(0, timeString.length - 6)} ${timeString.slice(
-2
)} ${dateString}`;
return Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "numeric",
day: "numeric",
month: "numeric",
year: "2-digit",
}).format(date);
};

0 comments on commit f4026fb

Please sign in to comment.