Try using utcToZonedTime()

To change the displayed date/time returned from format(), you must use either:

  • utcToZonedTime: when you want to know what the local date is in another timezone
  • zonedTimeToUtc: when you want to know what a date in another timezone is in the local timezone

Working Demo

Answer from User863 on Stack Overflow
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
Envato Tuts+
code.tutsplus.com › home › javascript
Using date-fns for Easy Date Manipulation | Envato Tuts+
July 28, 2023 - In this code, we parse the date from the dateString using the format yyyy-MM-dd, which corresponds to the provided date string. The third argument is the base date to use for calculating the parsed date. In this case, we use the current date as the base. Manipulating dates by adding or subtracting time intervals is a common requirement in date handling. date-fns provides a set of convenient functions to perform these operations with ease.
🌐
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 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ] The library is available as an npm package.
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
npm
npmjs.com › package › date-fns-tz
date-fns-tz - npm
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
🌐
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.
🌐
Snyk
snyk.io › advisor › date-fns › functions › date-fns.format
How to use the date-fns.format function in date-fns | Snyk
dateFormat(date) { return dateFns.format(date, 'YYYY-MM-DD HH:mm:ss'); } }, adarshpastakia / aurelia-ui-framework / src / calendar / ui-date.ts View on Github · set minute(m) { this.time = setMinutes(this.time, parseInt(m, 10)); this.dateChanged( toDate( format(this.date || new Date(), ...
Find elsewhere
🌐
LogSnag
logsnag.com › blog › handling-timezones-in-javascript-with-date-fns-tz
How to Handle Time-Zones in JavaScript with date-fns-tz | LogSnag
October 20, 2023 - Our first task is to format the date of the party in a specific time zone. date-fns-tz provides us with a function called formatInTimeZone for this.
🌐
GitHub
github.com › marnusw › date-fns-tz
GitHub - marnusw/date-fns-tz: Complementary library for date-fns v2 adding IANA time zone support · GitHub
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.
Author   marnusw
🌐
Tabnine
tabnine.com › home page › code › javascript › date-fns
date-fns.format JavaScript and Node.js code examples | Tabnine
"MMMM d, yyyy" : "MMMM dd, yyyy HH:MM:ss" ; return fs.format(new Date(fs.parseISO(time)), format); }
🌐
GitHub
github.com › date-fns › date-fns › issues › 489
Specify a time zone for format()? · Issue #489 · date-fns/date-fns
May 18, 2017 - I recently encountered a phenomenon in date-fns that broke a Node.js script of mine: const d = new Date('2017-01-23'); console.log(format(d, 'YYYY-MM-DD')); This code logs 2017-01-2...
Published   May 18, 2017
🌐
Fulcrumapp
help.fulcrumapp.com › en › articles › 4037876-date-manipulation-with-date-fns
Date Manipulation with date-fns | Fulcrum Help Center
The examples below assume all the date-fns modules are available in a full build. Subtract 10 days from a Fulcrum date field with subDays. // date: Thu Nov 07 2019 00:00:00 GMT-0500 (Eastern Standard Time) var result = datefns.subDays($date, 10); SETRESULT(result); // result: Mon Oct 28 2019 00:00:00 GMT-0400 (Eastern Daylight Time) Copy
🌐
Lloyd Atkinson
lloydatkinson.net › projects › 2023 › date-fns-additional
Useful Date Time Functions - Lloyd Atkinson
January 17, 2023 - Other ecosystems often have their popular date time library. For .NET, for example, NodaTime. date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js. Most of the functions I’ve built so far were either extracted out and refactored from other codebases I’ve worked on. For example, this site formats dates with a specific format.
🌐
GitHub
github.com › goomba › date-fns
GitHub - goomba/date-fns: 📅 custom formatting for durations
npm install @goomba/date-fns # or yarn add @goomba/date-fns · import { formatDuration } from '@goomba/date-fns' formatDuration({ days: 3 }, "d 'days ago'"); //=> "3 days ago"
Author   goomba