I faced with the same problem:

6 October 2019 in Australia is Daylight Saving Time Starts.

dh.parse('2019-10-06')

returns: Sat Oct 05 2019 23:00:00 GMT+1000 (Australian Eastern Standard Time)

Solution is adding info about time zone (one of):

  1. Add sign of absent time zone offset “Z” -- dh.parse('2019-10-06T00:00:00.000Z' )
  2. Add GMT -- dh.parse('2019-10-06 GMT' )
  3. Add +00:00 -- dh.parse('2019-10-06T00:00:00.000+00:00' )

]1)

Answer from Vlad 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." With the function-per-file style, you can pick just what you need and stop bloating your project with useless functionality.
🌐
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 // ]
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
Envato Tuts+
code.tutsplus.com › home › javascript
Using date-fns for Easy Date Manipulation | Envato Tuts+
July 28, 2023 - In addition to adding and subtracting days, date-fns provides functions for adding and subtracting months and years.
🌐
CodeSandbox
codesandbox.io › s › date-fns-adddays-ykxye
date-fns/addDays - CodeSandbox
November 16, 2021 - date-fns/addDays using @babel/runtime, date-fns
Published   Nov 16, 2021
🌐
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.
🌐
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 - Also notice how the method name is more expressive (addDays instead of just add), keeping things consistent and having one method to do one thing and one thing only. If you look at the list of posts on SitePoint’s JavaScript channel, you can see that some are listed as being published on a certain date, whereas others are listed as being published X days ago. It might take a while if you tried to implement this in vanilla JavaScript, but with date-fns this is a breeze – just use the formatDistance method.
Find elsewhere
🌐
Dev By RayRay
hasnode.byrayray.dev › how-to-easily-add-and-subtract-dates-in-javascript-date-fns-is-a-solid-choice
How to Easily Add and Subtract Dates in JavaScript — date-fns is a solid choice
July 5, 2023 - First, we have imported the addDays from date-fn's. We created a variable with a date and added 3, 7, and 31 days. Each util function in date-fns will return a new Date object. This is nice, so you can continue to add more calculations on top of it.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-date-fns
Quick Tour of date-fns, a Simple JavaScript Date Library | DigitalOcean
March 18, 2020 - 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 ·
🌐
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.
🌐
Medium
medium.com › @stheodorejohn › date-operations-in-javascript-with-date-fns-880bb182cec6
Date Operations in JavaScript with date-fns | by Theodore John.S | Medium
June 12, 2023 - Date manipulation is a common task in JavaScript development, and the date-fns library provides a powerful toolkit to simplify and enhance your date-related operations. In this article, we’ll explore ten activities you can perform with date-fns to supercharge your date manipulation capabilities.
🌐
Youmightnotneed
youmightnotneed.com › date-fns
You Might Not Need date-fns
Subtract the specified number of days from the given date. // https://date-fns.org/v3.5.0/docs/subDays import { subDays } from 'date-fns' // Subtract 10 days from 1 September 2014: subDays(new Date(2014, 8, 1), 10) // => Fri Aug 22 2014 00:00:00
🌐
Qiita
qiita.com › node.js
date-fnsのメソッドでできること #Node.js - Qiita
June 5, 2023 - そもそも前提として、date-fnsはNodeJS標準のDate型を使うライブラリです。parseした結果は標準のDate型で受け取りますし、formatしたい日付は標準のDate型で指定することができます。 しかし、利便性のためか、以下の4点だけ独自の型定義を提供しているらしい。 ... type Duration = { years?: number, months?: number, weeks?: number, days?: number, hours?: number, minutes?: number, seconds?: number, };
🌐
Qiita
qiita.com › javascript
date-fnsについて - Qiita
August 4, 2022 - 文字列をDateオブジェク... (日本標準時) 特定の日付に日付を加算、減算できる。 · addDays(new Date(2022, 4, 13), 1) // Sat May 14 2022 00:00:00 GMT+0900 (日本標準時) subDays(new Date(2022, ...
🌐
Zenn
zenn.dev › snjssk › articles › f05d1bcfeb9604
date-fns 使い方あれこれ
import { addDays } from 'date-fns' // 1日後 console.log(addDays(new Date(2021, 0, 1), 1)) -> Sat Jan 02 2021 00:00:00 GMT+0900 (日本標準時) // 10日後 console.log(addDays(new Date(2021, 0, 1), 10)) -> Mon Jan 11 2021 00:00:00 GMT+0900 (日本標準時)