//Parse date string to date object. Use parse
const dateString = '10-13-20';
const date = parse(dateString, 'MM-dd-yy', new Date()) // not MM-DD-YY
//Format date object to result string. Use format
const result = format(date, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")
console.log(result)
//Result will be like (the same with moment's result in my timezone):
// 2020-10-13T00:00:00.000+09:00
import { format, formatDistance, formatRelative, subDays } from 'date-fns'
format(new Date(), "'Today is a' eeee")
//=> "Today is a Tuesday"
formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"
formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
import { format, formatDistance, formatRelative, subDays } from 'date-fns'
format(new Date(), "'Today is a' eeee")
//=> "Today is a Saturday"
formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"
formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
const date = "2021-12-20"
console.log(format(parseISO(date), "dd-MM-yyyy"));
// output: 20-12-2021
format(new Date(), "'Today is a' eeee")