As you can see, with moment lib, we need 2 steps to get the result: parse string to Date object, then format date object to string.

Your code - format(new Date("10-13-20"), 'MM-DD-YY') is format step, try convert a date object to a string with format template is MM-DD-YY. But your date object is not correct.

The solution is to do the same as with moment lib:

  1. 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
    
  2. 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
    
Answer from hoangdv on Stack Overflow
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
... import { format, formatDistance, formatRelative, subDays } from 'date-fns' format(new Date(), "'Today is a' eeee") //=> "Today is a Monday" 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."...
🌐
npm
npmjs.com › package › date-fns
date-fns - npm
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 ...
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
GitHub
github.com › date-fns › date-fns
GitHub - date-fns/date-fns: ⏳ Modern JavaScript date utility library ⌛️
import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 ...
Author   date-fns
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-date-fns
Quick Tour of date-fns, a Simple JavaScript Date Library | DigitalOcean
March 18, 2020 - const format = require('date-fns/format'); const russianLocale = require('date-fns/locale/ru'); const stPattysDay = new Date('2020/03/17'); const formattedDate = format(stPattysDay, 'MMMM dd, yyyy', { locale: russianLocale }); console.log(formattedDate); // => "марта 17, 2020" The ability ...
🌐
Envato Tuts+
code.tutsplus.com › home › javascript
Using date-fns for Easy Date Manipulation | Envato Tuts+
July 28, 2023 - JavaScript's Date object has basic support for formatting dates, but it lacks support for custom formats. date-fns provides the format function for this purpose. In this example, we create a new Date object representing the current date. We then ...
🌐
Tabnine
tabnine.com › home page › code › javascript › date-fns
date-fns.format JavaScript and Node.js code examples | Tabnine
<ListItemDetail text={iMessage('label', 'created')} value={format(new Date(created), 'dd/MM/yyyy')} /> <ListItemDetail text={iMessage('label', 'updated')} value={format(new Date(updated), 'dd/MM/yyyy')} /> </List>
Find elsewhere
🌐
date-fns
date-fns.org › v1.30.1 › docs › format
date-fns format
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
SitePoint
sitepoint.com › blog › javascript › managing dates and times in javascript using date-fns
Managing Dates and Times in JavaScript Using date-fns — SitePoint
November 13, 2024 - This will format the output like so: Wednesday, September 16th, 2020. You can find a full list of formatting options in the docs. If you have a website in multiple languages, then date-fns makes it simple to internationalize times and dates.
🌐
Snyk
snyk.io › advisor › date-fns › date-fns code examples
Top 5 date-fns Code Examples | Snyk
export const ScopeDays = (props: ScopeDaysProps) => { const { tasks, date } = props; const days = groupBy(tasks, t => formatDate(parseDate(t.date.split(' ')[0]))); const start = startOfMonth(date); let end = endOfMonth(date); const now = new Date(); if (end > now) { end = now; } if (end > start) { // Ensure that days before the current day are given a scope, even with no tasks eachDayOfInterval({ start, end }).forEach(day => { const key = formatDate(day); if (!days[key]) days[key] = []; }); }
🌐
YouTube
youtube.com › helpcodeit
Formatting Dates using Date-fns - YouTube
The library used is located at date-fns.org and is super easy to use. Check out their site for more info. Hope this helps with basic formatting of dates in a...
Published   September 27, 2023
Views   1K
🌐
GitHub
github.com › date-fns › date-fns › blob › main › src › format › index.ts
date-fns/src/format/index.ts at main · date-fns/date-fns
import { longFormatters } from "../_lib/format/longFormatters/index.ts"; ... * Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. ... * and `options.firstWeekContainsDate` (compare [getISOWeekYear](https://date-fns.org/docs/getISOWeekYear)
Author   date-fns
🌐
DEV Community
dev.to › marinamosti › -formatting-and-modifying-javascript-dates-with-date-fns-3df2
Formatting and modifying JavaScript dates with date-fns - DEV Community
September 23, 2019 - Ok, so formatting is a very straight forward task. But date-fns also supports a simple way to localize formatted date output. Let's grab our previous example and change it to a French locale, with a full month-name format. We just need to require the locale, and pass it to the format option.
🌐
Handsontable
handsontable.com › home › hands-on: format date with date-fns and day.js in a data grid
Hands-on: Format date with date-fns and day.js in a data grid
August 25, 2023 - Learn how to utilize the day.js and date-fns libraries to format a date string within a Handsontable data grid by employing cell renderers.
🌐
npm
npmjs.com › package › date-fns-tz
date-fns-tz - npm
Since date-fns always returns a plain JS Date, which implicitly has the current system's time zone, helper functions are provided for handling common time zone related use cases. This function takes a Date instance in the system's local time or an ISO8601 string, and an IANA time zone name or offset string. It then formats this date in the target time zone regardless of the system's local time zone.
      » npm install date-fns-tz
    
Published   Sep 30, 2024
Version   3.2.0
Author   Marnus Weststrate
🌐
CodePen
codepen.io › melissamcewen › pen › bGwjaGV
datetime example: date-fns
import { format, add, getHours, ... = add(now, {days: 7}) // Now formatted like "Monday, November 23, 5pm" const dateFormatted = format(now, "EEEE',' MMMM d',' ha") // Date and time on Lord Howe Island // We need date-fns-tz ...