date.ts 422 B

123456789101112131415
  1. import { formatDistanceToNowStrict, format as fnsFormat } from 'date-fns';
  2. export const format = (date: string | Date, format: string) => {
  3. return fnsFormat(new Date(date), format);
  4. };
  5. export const dateTemplate = (date: string | Date) => {
  6. return format(date, 'MMMM d, yyyy');
  7. };
  8. export function distanceToNow(date: string | Date) {
  9. return formatDistanceToNowStrict(new Date(date), {
  10. addSuffix: true,
  11. });
  12. }