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.
🌐
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
Discussions

How to convert ISO to date using date-fns
format(parseISO('2022-04-19T08:59:10.177Z'), 'eeee do MMM, yyyy')
More on reddit.com
🌐 r/reactjs
11
0
October 10, 2020
What library do you use to handle dates?
When I'm asked to handle dates, I just quit and find a job elsewhere. More on reddit.com
🌐 r/reactjs
86
30
June 7, 2023
🌐
DEV Community
dev.to › dmtrkovalenko › you-might-not-need-date-fns-23f7
You might not need date-fns - DEV Community
May 10, 2021 - But one day I said that date-fns ... date-fns' maintainer blocked me everywhere because it says that you might not need it. So probably this thread contains some useful information for people that choosing date lib – so I decided to share it in the blog as well! Hope you will have some fun reading it :) That's it for prerequisites so let's start the discussion · First of all, when you need to only show date values in the user-readable format – you can ...
🌐
Fulcrumapp
help.fulcrumapp.com › en › articles › 4037876-date-manipulation-with-date-fns
Date Manipulation with date-fns | Fulcrum Help Center
Working with JavaScript dates and times can quickly become challenging and date-fns provides over 140 functions for comparing, manipulating, and formatting dates and timestamps.
Find elsewhere
🌐
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 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.
Author   date-fns
🌐
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.
🌐
date-fns
date-fns.org › v2.0.0-alpha.25 › docs › format
Date formats
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
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
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-date-fns
Quick Tour of date-fns, a Simple JavaScript Date Library | DigitalOcean
March 18, 2020 - The ability to calculate the differences between 2 dates is important for a date manipulation library. date-fns provides several functions for calculating this. For example, we can calculate the days from January 1st to Christmas (as well as “business days”!): const format = require('date-fns/format'); const addYears = require('date-fns/addYears'); const differenceInDays = require('date-fns/differenceInDays'); const differenceInBusinessDays = require('date-fns/differenceInBusinessDays') const startDate = new Date('2020/01/01'); const endDate = new Date('2020/12/24'); const daysBetween = differenceInDays(endDate, startDate); const workdaysBetween = differenceInBusinessDays(endDate, startDate); console.log(daysBetween); // => 358 console.log(workdaysBetween); // => 256
🌐
Laravel
laravel.cm › articles › how-to-use-dates-in-javascript-with-the-date-fns-library-2
How to Use Dates in JavaScript with the date-fns Library | Laravel Cameroon
January 8, 2025 - To get started , you need to install the library , Use npm or yarn to add it to your project npm install date-fns or yarn add date-fns · Formatting dates is one of the most common tasks in date handling , with date-fns , you can use the format function to convert a Date object into readable string.
🌐
DevDocs
devdocs.io › date_fns
DevDocs — date-fns documentation
date-fns 2.29.2 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
🌐
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 - ... import { format, utcToZonedTime ... = utcToZonedTime(today, timeZone); console.log(` Time in Munich: ${format(today, 'yyyy-MM-dd HH:mm:ss')} Time in Brisbane: ${format(timeInBrisbane, 'yyyy-MM-dd HH:mm:ss')} `); // Time in ...
🌐
Michaelbonner
date-fns.michaelbonner.dev
date-fns format helper
A simple tool to help keep track of commonly used date formats. The tool is also helpful to test custom date formats.
🌐
Yarn
classic.yarnpkg.com › en › package › date-fns
date-fns
Fast, reliable, and secure dependency management.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › DateTimeFormat
Intl.DateTimeFormat - JavaScript | MDN
The initial value of the [Symbol.toStringTag] property is the string "Intl.DateTimeFormat". This property is used in Object.prototype.toString(). ... Getter function that formats a date according to the locale and formatting options of this DateTimeFormat object.
🌐
StackBlitz
stackblitz.com › edit › js-fnwevt
date format using date-fns - StackBlitz
StackOverflow #54443161 Answer for question: https://stackoverflow.com/questions/54443161/parse-and-format-date-in-string/54443704#54443704 Using date-fns 2.0.0-alpha.27