tailwind-nextjs-blog/lib/utils/formatDate.ts

15 lines
326 B
TypeScript
Raw Normal View History

2022-10-17 23:37:01 +08:00
import siteMetadata from '@/data/siteMetadata';
2022-07-17 21:40:41 +08:00
const formatDate = (date: string) => {
const options: Intl.DateTimeFormatOptions = {
2022-07-17 21:40:41 +08:00
year: 'numeric',
month: 'long',
day: 'numeric',
2022-10-17 23:37:01 +08:00
};
const now = new Date(date).toLocaleDateString(siteMetadata.locale, options);
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +08:00
return now;
};
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +08:00
export default formatDate;