moment.js is great but sometimes you don't want to pull a large number of dependencies for simple things.

The following works as well:

    var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
    var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1);
    
    console.log(localISOTime)  // => '2015-01-26T06:40:36.181'

The slice(0, -1) gets rid of the trailing Z which represents Zulu timezone and can be replaced by your own.

Answer from yegodz on Stack Overflow
🌐
GitHub
gist.github.com › lvl99 › af20ee34f0c6e3984b29e8f0f794a319
Date ISO string without timezone information · GitHub
Date ISO string without timezone information · Raw · date-iso-string-without-timezone.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
🌐
GitHub
github.com › date-fns › date-fns › issues › 2151
formatISO doesn't use UTC (Z) timezone · Issue #2151 · date-fns/date-fns
January 12, 2021 - When making a sanity check of now.toISOString() === formatISO(now) (with const now = new Date()), it fails due to a timezone difference, as the formatISO doesn't match the browser's toISOString, which explicitly claims that The timezone is always ...
Author   scscgit
🌐
GitHub
gist.github.com › barbietunnie › 67d10b59f7716e3ff5892d70dd9a3cfa
Format JS Date in ISO-8601 without timezone issues · GitHub
The following function provides an easy way to format Javascript dates in ISO-8601 format without using date.toISOString(), which could lead to timezone issues as the date is first converted to UTC which could lead to discrepancies in the result in certain timezones.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-create-date-without-timezone
How to Create a Date without Timezone in JavaScript | bobbyhadz
This is because my time zone is 3 hours ahead of Coordinated Universal time (UTC). To create a Date without the timezone, we called the toISOString() method on the Date object and removed the character Z from the ISO string.
🌐
GitHub
gist.github.com › peterbraden › 752376
toISOString with timezone support · GitHub
toISOString with timezone support · Raw · Local ISO String for Date · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
DEV Community
dev.to › shubhampatilsd › removing-timezones-from-dates-in-javascript-46ah
Removing Timezones from Dates in Javascript - DEV Community
April 23, 2023 - Now here is the actual implementation ... * 60000; //offset in milliseconds const withoutTimezone = new Date(date.valueOf() - tzoffset) .toISOString() .slice(0, -1); return withoutTimezone; };...
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Date › toISOString
Date.prototype.toISOString() - JavaScript
If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request. ... A string representing the given date in the ISO 8601 format according to universal time. This method was standardized in ECMA-262 5th edition.
Find elsewhere
🌐
GitHub
gist.github.com › loilo › 736d5beaef4a96d652f585b1b678a12c
ISO 8601 date string – like Date.prototype.toISOString(), but with local timezone offset
ISO 8601 date string – like Date.prototype.toISOString(), but with local timezone offset · Raw · get-local-iso-string.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
W3Schools
w3schools.com › jsref › jsref_toisostring.asp
JavaScript Date toISOString() Method
The toISOString() method returns a date object as a string, using the ISO standard.
🌐
GitHub
github.com › iamkun › dayjs › issues › 504
dayjs.toISOString() without seconds and/or milliseconds · Issue #504 · iamkun/dayjs
January 21, 2019 - How can I get a ISO string date format without the seconds and/or milliseconds on the output? I know that I can do this import dayjs from "dayjs"; document.getElementById("app").innerHTML = dayjs("18/09/1995", "DD/MM/YYYY") .toISOString(...
Author   waghcwb
🌐
GitHub
github.com › moment › moment › issues › 4511
[BUG] toISOString don't return timestamp in UTC · Issue #4511 · moment/moment
December 27, 2017 - Hi all, I have some trouble with the toISOString() method. I want to get the UTC of date but the toISOString() method return my local timezone (GMT +1). This moment("2018-03-23").toISOString() should return 2018-03-23T00:00:00.000Z but when i try it i have 2018-03-22T23:00:00.000Z.
Author   workfel
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-iso-date-without-time
Get ISO Date without Milliseconds or Time in JavaScript | bobbyhadz
Copied!const date = new Date(); // ✅ If you have a Date object const [withoutTime] = date.toISOString().split('T'); console.log(withoutTime); // 👉️ 2023-07-27 // ✅ If you have a plain ISO string const [withoutT] = '2022-11-14T00:55:31.820Z'.split('T'); console.log(withoutT); // 👉️ "2022-11-14" The code for this article is available on GitHub ·
🌐
MSR
rajamsr.com › home › the best way to convert javascript date to iso string
The Best Way to Convert JavaScript Date to ISO String | MSR - Web Dev Simplified
February 24, 2024 - If you need an ISO string without seconds and milliseconds, you can modify the toISOString() result:
🌐
UsefulAngle
usefulangle.com › post › 30 › javascript-get-date-time-with-offset-hours-minutes
How to get DateTime with Timezone Offset (8601 format) in Javascript
Javascript has a toISOString method that gives a datetime in ISO-8601 format. But it gives datetime strings only in UTC format, YYYY-MM-DDTHH:mm:ss.sssZ. It does not give a timezone offset in hours and minutes.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toISOString
Date.prototype.toISOString() - JavaScript | MDN
The toISOString() method of Date instances returns a string representing this date in the date time string format, a simplified format based on ISO 8601, which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively).
🌐
GitHub
github.com › iamkun › dayjs › issues › 2408
toISOString() is inconsistent with set timezone · Issue #2408
const dayjsObj = dayjs('2020-01-02T15:14:59.741774+00:00').tz('America/New_York', true); console.log(dayjsObj.toISOString()); gives inconsistent results depending on the timezone the computer is running it in. For example, a computer in the America/New_York timezone would log out 2020-01-02T15:14:59.741Z whereas a computer in UTC would log out 2020-01-02T20:14:59.741Z.
🌐
GitHub
github.com › su-fit-vut › kachna-online › issues › 55
Handle time zones properly · Issue #55 · su-fit-vut/kachna-online
August 2, 2021 - In the backend, all dates and times are handled as if they were in the current timezone (there's even a Npgsql override that ensures this). The .toISOString() method of JS Date objects returns the date in UTC without timezone (suffixed with 'Z'), ...
Author   ondryaso