As new Date().toISOString() will return current UTC time, to get local time in ISO String format we have to get time from new Date() function like the following method

document.write(new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('.')[0]);

Answer from jafarbtech on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
DD is the day of the month, with two digits (01 to 31). Defaults to 01. T is a literal character, which indicates the beginning of the time part of the string. The T is required when specifying the time part. HH is the hour, with two digits (00 to 23). As a special case, 24:00:00 is allowed, and is interpreted as midnight at the beginning of the next day. Defaults to 00. mm is the minute, with two digits (00 to 59). Defaults to 00. ss is the second, with two digits (00 to 59).
Discussions

Format date at 'YYYY:MM:DD HH:MM;SS'
Hello. How can you format the date in the logs? now I have it '23 Nov 2023 hh:mm:ss' it must have been so 'YYYY:MM:DD HH:MM;SS' Writing a function just adds the date again(( const currentDate = new Date(); const formattedDateTime = currentDate.toISOString().replace(/T/, ' ').replace(/\..+/, ... More on discourse.nodered.org
🌐 discourse.nodered.org
0
November 23, 2023
JS date and Time Format - JavaScript - SitePoint Forums | Web Development & Design Community
Hi I am trying to change the format of below date: Current format: Tue Feb 17 03:33:27 CST 2009 To Expected format: yyyy-mm-dd:hh:mm I have tried few Google pages for solution but not able to implement it. Can any one help me to find the solution? Thanks, More on sitepoint.com
🌐 sitepoint.com
0
January 1, 2009
How to format a Date in MM/dd/yyyy HH:mm:ss format in JavaScript? - Stack Overflow
Possible Duplicate: Formatting a date in javascript I know other possible formats in JavaScript Date object but I did not get on how to format the date to MM/dd/yyyy HH:mm:ss format. Please l... More on stackoverflow.com
🌐 stackoverflow.com
Should we always output an ISO date to JavaScript using ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")?
I interop with JavaScript dates all the time, and I just use the 'o' format string when passing dates via JSON. More on reddit.com
🌐 r/csharp
23
0
November 25, 2025
🌐
GitHub
gist.github.com › Ivlyth › c4921735812dd2c0217a
format javascript date to format "YYYY-mm-dd HH:MM:SS" · GitHub
function NOW() { var date = new Date(); var aaaa = date.getUTCFullYear(); var gg = date.getUTCDate(); var mm = (date.getUTCMonth() + 1); if (gg < 10) gg = "0" + gg; if (mm < 10) mm = "0" + mm; var cur_day = aaaa + "-" + mm + "-" + gg; var hours = date.getUTCHours() var minutes = date.getUTCMinutes() var seconds = date.getUTCSeconds(); if (hours < 10) hours = "0" + hours; if (minutes < 10) minutes = "0" + minutes; if (seconds < 10) seconds = "0" + seconds; return cur_day + " " + hours + ":" + minutes + ":" + seconds; } console.log(NOW());
🌐
Medium
trymysolution.medium.com › javascript-date-as-in-yyyy-mm-dd-hh-mm-ss-format-or-mm-dd-yyyy-hh-mm-ss-a0c96e8fa888
JavaScript Date as in YYYY-MM-DD hh:mm:ss Format or MM/DD/YYYY hh:mm:ss | by Yogesh D V | Medium
April 11, 2023 - function padTwoDigits(num: number) ... string = "-") { // :::: Exmple Usage :::: // The function takes a Date object as a parameter and formats the date as YYYY-MM-DD hh:mm:ss....
🌐
Node-RED
discourse.nodered.org › general
Format date at 'YYYY:MM:DD HH:MM;SS' - General - Node-RED Forum
November 23, 2023 - Hello. How can you format the date in the logs? now I have it '23 Nov 2023 hh:mm:ss' it must have been so 'YYYY:MM:DD HH:MM;SS' Writing a function just adds the date again(( const currentDate = new Date(); const formattedDateTime = currentDate.toISOString().replace(/T/, ' ').replace(/\..+/, ''); const { loggingLevel } = msg; delete msg.loggingLevel; const messageToLog = `${formattedDateTime} - [info] [function:Log message to system console] ${JSON.stringify(msg)}`; if (loggingLevel === '...
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
ISO dates can be written with added hours, minutes, and seconds (YYYY-MM-DDTHH:MM:SSZ): const d = new Date("2015-03-25T12:00:00Z"); Try it Yourself » · Date and time is separated with a capital T. UTC time is defined with a capital letter Z. If you want to modify the time relative to UTC, remove the Z and add +HH:MM or -HH:MM instead:
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › how-to-format-the-current-date-in-mm-dd-yyyy-hhmmss-format-using-node-js
How to format the current date in MM/DD/YYYY HH:MM:SS format using Node? - GeeksforGeeks
July 23, 2025 - This code utilizes the `moment` library to format the current date and time. The first `console.log` prints the date and time in the MM/DD/YYYY HH:mm:ss format (24-hour clock), while the second one uses the hh:mm:ss format (12-hour clock).
🌐
SitePoint
sitepoint.com › javascript
JS date and Time Format - JavaScript - SitePoint Forums | Web Development & Design Community
January 1, 2009 - Hi I am trying to change the format of below date: Current format: Tue Feb 17 03:33:27 CST 2009 To Expected format: yyyy-mm-dd:hh:mm I have tried few Google pages for solution but not able to implement it. Can any …
Top answer
1 of 4
181

[Addendum 12/2022]: Here's a library to format dates using Intl.DateTimeFormat.

[Addendum 01/2024]: And here is a (ES-)Date manipulation library

Try something like this

var d = new Date,
    dformat = [d.getMonth()+1,
               d.getDate(),
               d.getFullYear()].join('/')+' '+
              [d.getHours(),
               d.getMinutes(),
               d.getSeconds()].join(':');

If you want leading zero's for values < 10, use this number extension

Number.prototype.padLeft = function(base,chr){
    var  len = (String(base || 10).length - String(this).length)+1;
    return len > 0? new Array(len).join(chr || '0')+this : this;
}
// usage
//=> 3..padLeft() => '03'
//=> 3..padLeft(100,'-') => '--3' 

Applied to the previous code:

var d = new Date,
    dformat = [(d.getMonth()+1).padLeft(),
               d.getDate().padLeft(),
               d.getFullYear()].join('/') +' ' +
              [d.getHours().padLeft(),
               d.getMinutes().padLeft(),
               d.getSeconds().padLeft()].join(':');
//=> dformat => '05/17/2012 10:52:21'

See this code in [jsfiddle][1]

[edit 2019] Using ES20xx, you can use a template literal and the new padStart string extension.

const dt = new Date();
const padL = (nr, len = 2, chr = `0`) => `${nr}`.padStart(2, chr);

console.log(`${
    padL(dt.getMonth()+1)}/${
    padL(dt.getDate())}/${
    dt.getFullYear()} ${
    padL(dt.getHours())}:${
    padL(dt.getMinutes())}:${
    padL(dt.getSeconds())}`
);

2 of 4
73

You can always format a date by extracting the parts and combine them using string functions in desired order:

function formatDate(date) {
  let datePart = [
    date.getMonth() + 1,
    date.getDate(),
    date.getFullYear()
  ].map((n, i) => n.toString().padStart(i === 2 ? 4 : 2, "0")).join("/");
  let timePart = [
    date.getHours(),
    date.getMinutes(),
    date.getSeconds()
  ].map((n, i) => n.toString().padStart(2, "0")).join(":");
  return datePart + " " + timePart;
}

let date = new Date();
console.log("%o => %s", date, formatDate(date));

🌐
Reddit
reddit.com › r/csharp › should we always output an iso date to javascript using tostring("yyyy-mm-dd't'hh:mm:ss.fff'z'")?
r/csharp on Reddit: Should we always output an ISO date to JavaScript using ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'")?
November 25, 2025 -

Was chatting with chatgpt about how date format outputs can go wrong between back end and javascript, and I'd just like to have this confirmed by humans if possible. :)

  1. The first point was that JS is only accuate to milliseconds, so using ToString("o") will silently lose precision (from 7 digits to 3 digits) when interpreted in JS.

    e.g. Output from ToString("o"):

    2025-11-25T01:10:28.4156402+00:00

    Javascript only sees milliseconds:

    2025-11-25T01:10:28.415+00:00

    Apparently some older browsers / devices have historically sometimes completely failed to parse a string more than 3 digit precision, but mainly the round-trip value will be different, not exactly the same. Hence it is "safer" to explicitly use "yyyy-MM-ddTHH:mm:ss.fffZ", to say "just note we only have 3 digit precision to work with here".

  2. The second point was that single quotes should be around the 'T' and 'Z' is also safer because the ToString() parser doesn't actually recognise T and Z as ISO date tokens at all - it sees them as "invalid string format tokens" and outputs them as-is - which means potentially that behaviour might change in future. (One can use "+00:00" instead of "Z" but single quotes are still needed around the "T".)

Bottom line, it seems the "safest" format string to serialise a date for javascript is "yyyy-MM-dd'T'HH:mm:ss.fff'Z'" (or "yyyy-MM-dd'T'HH:mm:ss.fff+00:00"), with the single quotes and explicitly stating 3-digit precision.

So is that what everyone does when serialising for javascript, or are there also other, equally round-trip sate, ways? i.e. Should I go ahead and adopt this as standard, or are there other considerations?

(ed formatting)

🌐
UiPath Community
forum.uipath.com › help › activities
Converting String into DateTime format - "yyyy-MM-dd HH:mm:ss" - Activities - UiPath Community Forum
May 22, 2024 - Hi All, Im converting a string “MM/dd/yyyy HH:mm:ss” to a DateTime “yyyy:MM:dd HH:mm:ss” using: Datetime.ParseExact(str_datetime, “yyyy-MM-dd hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture) I start of by converting the string to the new format: DateTime.ParseExact(str_datetime, “dd/MM/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd HH:mm:ss”) this works ok. then I convert the new string into a DateTime. using: Datetime.ParseExact(str_datet...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-datetime-to-yyyy-mm-dd-hhmmss-in-momentjs
How to Format Datetime to YYYY-MM-DD HH:MM:SS in Moment.js? - GeeksforGeeks
July 23, 2025 - We first convert the input date string into a Unix timestamp, then use moment.unix() to create a new Moment.js object from this timestamp. Finally, we format this object to 'YYYY-MM-DD HH:mm:ss', resulting in the desired date format.
🌐
ServiceNow Community
servicenow.com › community › sysadmin-forum › make-date-time-value-in-format-to-mm-dd-yyyy-hh-mm-ss-and-add-14 › td-p › 2501915
Make date/time value in format to MM/dd/yyyy hh:mm:ss and add 14 days
March 12, 2023 - var task = new GlideRecord('cert_follow_on_task'); task.addEncodedQuery('due_dateISEMPTY^active=true^stateNOT IN3,4,7^state=2^assigned_to=NULL'); task.query(); while (task.next()) { var date = new GlideDateTime(); date.addDays(14); task.due_date = date.getDateFormatted('MM/dd/yyyy hh:mm:ss'); task.update(); }
🌐
GitHub
gist.github.com › mohokh67 › e0c5035816f5a88d6133b085361ad15b
Get YYYY-MM-DD HH-MM-SS in JavaScript · GitHub
Get YYYY-MM-DD HH-MM-SS in JavaScript · Raw · timestamp-formatter.md · const formatedTimestamp = ()=> { const d = new Date() const date = d.toISOString().split('T')[0]; const time = d.toTimeString().split(' ')[0].replace(/:/g, '-'); return `${date} ${time}` } Sign up for free to join this conversation on GitHub.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › show-current-date-time-in-yyyy-mm-dd-hh-mm-ss-format-for-a-date › td-p › 2754288
Show current date/time in YYYY-MM-DD HH:MM:SS format for a date/time field using Client Script
December 6, 2023 - var d = new Date(); // Check your condition if (newValue == 'true') { // Format the date into YYYY-MM-DD HH:MM:SS var formattedDate = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + // Months are zero-based ('0' + d.getDate()).slice(-2) + ' ' + ('0' + d.getHours()).slice(-2) ...
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
The string format should be: YYYY-MM-DDTHH:mm:ss.sssZ, where: YYYY-MM-DD – is the date: year-month-day. The character "T" is used as the delimiter. HH:mm:ss.sss – is the time: hours, minutes, seconds and milliseconds.