Call the toISOString() method:

var dt = new Date("30 July 2010 15:05 UTC");
document.write(dt.toISOString());

// Output:
//  2010-07-30T15:05:00.000Z
Answer from Robert Harvey on Stack Overflow
🌐
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 ...
Discussions

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
Javascript Date Now (UTC) in yyyy-mm-dd HH:mm:ss format - Stack Overflow
My brain must be utterly fried, but I cannot for the life of me figure out how to get the current date and time in UTC formatted as a string. No matter what I do, I just get local. I have the follo... More on stackoverflow.com
🌐 stackoverflow.com
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
Parsing current localtime in 'YYYY-MM-DD'T'hh:mm:ss.ssssssTZD' format
If you can live with the limitations of Date: > new Date('2022-03-21T12:29:01.339916+00:00').toISOString() '2022-03-21T12:29:01.339Z' If you need more (e.g. support for time zones beyond Z and the local time zone), you can take a look at the Temporal API which is currently at stage 3 of the TC39 process. That means it’s not yet standard JavaScript, but might be added to ES2023 and there are polyfills you can use. More on reddit.com
🌐 r/learnjavascript
2
3
April 21, 2022
🌐
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).
🌐
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) { return num.toString().padStart(2, "0"); } function dateInYyyyMmDdHhMmSs(date: Date, dateDiveder: string = "-") { // :::: Exmple Usage :::: // The function takes a Date object as a parameter and formats the ...
🌐
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:
🌐
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.
🌐
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.
Find elsewhere
🌐
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'
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));

🌐
Darkthread
blog.darkthread.net › blog › js-date-yyyymmdd-hhmmss
JSON UTC 時間轉 yyyy-MM-dd HH:mm:ss 格式本地時間之香草 JavaScript 極簡解法-黑暗執行緒
直接取上方的 options,不介意中文字的上下午的話,使用本地化 "zh-TW" 可輸出為: console.log(new Intl.DateTimeFormat("zh-TW", options).format(date)); // 2022/10/27 下午4:00:30 · 有部分寫的是「yyyy-MM-mm」是不是寫錯了? to Ike,Yes, 連文章標題都是錯的,真佩服我自己... 感謝~ 也佩服我自己,兩年後再看,才發現 XD ... 2025-11-24 Ike JSON UTC 時間轉 yyyy-MM-dd HH:mm:ss 格式本地時間之香草 JavaScript 極簡解法 也佩服我自己,兩年後再看,才發現 XD
🌐
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 === '...
🌐
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) ...
🌐
Reddit
reddit.com › r/learnjavascript › parsing current localtime in 'yyyy-mm-dd't'hh:mm:ss.sssssstzd' format
r/learnjavascript on Reddit: Parsing current localtime in 'YYYY-MM-DD'T'hh:mm:ss.ssssssTZD' format
April 21, 2022 -

Is there a way to parse the current localtime in the below format using JavaScript?

Format: YYYY-MM-DD'T'hh:mm:ss.ssssssTZD
YYYY = four-digit year
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
s = six digits representing a decimal fraction of a second
TZD = time zone designator (Z or +hh:mm or -hh:mm)

Example: 2022-03-21T12:29:01.339916+00:00

🌐
SitePoint
sitepoint.com › javascript
JS date and Time Format - JavaScript - SitePoint Forums | Web Development & Design Community
January 2, 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 …
🌐
NewbeDEV
newbedev.com › csharp-javascript-format-date-yyyy-mm-dd-hh-mm-ss-code-example
javascript format date yyyy-mm-dd hh mm ss code example
let date_ob = new Date(); // adjust ... date_ob.getSeconds(); // prints date & time in YYYY-MM-DD HH:MM:SS format console.log(year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds);...
🌐
Codegrepper
codegrepper.com › code-examples › javascript › convert+date+to+yyyy-mm-dd+hh+mm+ss+in+javascript
convert date to yyyy-mm-dd hh mm ss in javascript Code Example
var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; document.write(today);
🌐
Codegrepper
codegrepper.com › code-examples › javascript › javascript+format+date+yyyy-mm-dd+hh+mm+ss
javascript format date yyyy-mm-dd hh mm ss Code Example
April 28, 2020 - var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; document.write(today);