Sadly, there is no flexible, built-in "format" method for JS Date objects, so you have to do it manually (or with a plug-in/library). Here is how you would do it manually:

function formatDate(dateVal) {
    var newDate = new Date(dateVal);

    var sMonth = padValue(newDate.getMonth() + 1);
    var sDay = padValue(newDate.getDate());
    var sYear = newDate.getFullYear();
    var sHour = newDate.getHours();
    var sMinute = padValue(newDate.getMinutes());
    var sAMPM = "AM";

    var iHourCheck = parseInt(sHour);

    if (iHourCheck > 12) {
        sAMPM = "PM";
        sHour = iHourCheck - 12;
    }
    else if (iHourCheck === 0) {
        sHour = "12";
    }

    sHour = padValue(sHour);

    return sMonth + "-" + sDay + "-" + sYear + " " + sHour + ":" + sMinute + " " + sAMPM;
}

function padValue(value) {
    return (value < 10) ? "0" + value : value;
}

Using your example date . . .

formatDate("Wed May 27 10:35:00 EDT 2015")  ===>  "05-27-2015 10:35 AM"
Answer from talemyn on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
const date = new Date("2020-05-12T23:50:21.817Z"); date.toString(); // Tue May 12 2020 18:50:21 GMT-0500 (Central Daylight Time) date.toDateString(); // Tue May 12 2020 date.toTimeString(); // 18:50:21 GMT-0500 (Central Daylight Time) date[Symbol.toPrimitive]("string"); // Tue May 12 2020 18:50:21 GMT-0500 (Central Daylight Time) date.toISOString(); // 2020-05-12T23:50:21.817Z date.toJSON(); // 2020-05-12T23:50:21.817Z date.toUTCString(); // Tue, 12 May 2020 23:50:21 GMT date.toLocaleString(); // 5/12/2020, 6:50:21 PM date.toLocaleDateString(); // 5/12/2020 date.toLocaleTimeString(); // 6:50:21 PM
🌐
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'
🌐
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....
🌐
W3docs
w3docs.com › javascript
How to Format a JavaScript Date
moment().format('YYYY-MM-DD HH:m:s'); ... in 13 hours · The .format() method constructs a string of tokens that refer to a particular component of date (like day, month, minute, or am/pm)....
🌐
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

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));

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-current-date-in-mm-dd-yyyy-hhmmss-format-using-javascript
How to format current date in MM/DD/YYYY HH:MM:SS format using ...
July 12, 2025 - Given a date and the task is to format the current date in MM/DD/YYYY HH:MM:SS format. Here are a few of the most techniques discussed with the help of JavaScript.
🌐
Tabnine
tabnine.com › home › how to format date in javascript
How to Format Date in JavaScript - Tabnine
July 25, 2024 - In this example we used the toLocaleString() method to apply the “English-US” time format. The output matches the US English common time format: D/MM/YYYY HH:MM:SS AM/PM.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-date-yyyy-mm-dd-hh-mm-ss
Format a Date as YYYY-MM-DD hh:mm:ss in JavaScript | bobbyhadz
We used the addition (+) operator to add a space in the middle of the strings to get the date and time formatted as YYYY-MM-DD hh:mm:ss.
🌐
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:
🌐
Stevenlevithan
blog.stevenlevithan.com › archives › javascript-date-format › comment-page-2
JavaScript Date Format
0 : date.getTimezoneOffset(), flags = { d: d, dd: pad(d), ddd: dF.i18n.dayNames[D], dddd: dF.i18n.dayNames[D + 7], m: m + 1, mm: pad(m + 1), mmm: dF.i18n.monthNames[m], mmmm: dF.i18n.monthNames[m + 12], yy: String(y).slice(2), yyyy: y, h: H % 12 || 12, hh: pad(H % 12 || 12), H: H, HH: pad(H), M: M, MM: pad(M), s: s, ss: pad(s), l: pad(L, 3), L: pad(L > 99 ? Math.round(L / 10) : L), t: H < 12 ? "a" : "p", tt: H < 12 ? "am" : "pm", T: H < 12 ?
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
- ISO 8601: YYYY-MM-DDTHH:mm:ss.sssZ (e.g. 2022-05-30T00:00:00.000Z) - Short date: mm/dd/yyyy or dd/mm/yyyy (e.g. 04/24/2023 or 24/04/2023) - Long date: MMMM dd, yyyy (e.g. April 24, 2023) - RFC 2822: EEE, dd MMM yyyy HH:mm:ss GMT (e.g. Mon, 24 Apr 2023 00:00:00 GMT) - Unix timestamp: the number ...
Top answer
1 of 2
37

You can fully format the string as mentioned in other posts. But I think your better off using the locale functions in the date object?

var d = new Date("2017-03-16T17:46:53.677"); 
console.log( d.toLocaleString() ); 

edit :

ISO 8601 ( the format you are constructing with ) states the time zone is appended at the end with a [{+|-}hh][:mm] at the end of the string.

so you could do this :

var tzOffset = "+07:00" 
var d = new Date("2017-03-16T17:46:53.677"+ tzOffset);
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677"); //  assumes local time. 
console.log(d.toLocaleString());
var d = new Date("2017-03-16T17:46:53.677Z"); // UTC time
console.log(d.toLocaleString());

edit :

Just so you know the locale function displays the date and time in the manner of the users language and location. European date is dd/mm/yyyy and US is mm/dd/yyyy.

var d = new Date("2017-03-16T17:46:53.677");
console.log(d.toLocaleString("en-US"));
console.log(d.toLocaleString("en-GB"));

2 of 2
10

Here we go:

var today = new Date();
var day = today.getDate() + "";
var month = (today.getMonth() + 1) + "";
var year = today.getFullYear() + "";
var hour = today.getHours() + "";
var minutes = today.getMinutes() + "";
var seconds = today.getSeconds() + "";

day = checkZero(day);
month = checkZero(month);
year = checkZero(year);
hour = checkZero(hour);
minutes = checkZero(minutes);
seconds = checkZero(seconds);

console.log(day + "/" + month + "/" + year + " " + hour + ":" + minutes + ":" + seconds);

function checkZero(data){
  if(data.length == 1){
    data = "0" + data;
  }
  return data;
}

🌐
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. GitHub Gist: instantly share code, notes, and snippets.
🌐
DEV Community
dev.to › riversun › introducing-a-handy-javascript-date-formatting-function-5cd7
Introducing a handy JavaScript date formatting function. - DEV Community
February 19, 2020 - 'PM' : 'AM') .replace(/m{1,2}/g, m => pad(date.getMinutes(), m)) .replace(/s{1,2}/g, m => pad(date.getSeconds(), m)) .replace(/S{3}/g, m => pad(date.getMilliseconds(), m)) .replace(/[E]+/g, m => _days[date.getDay()]) .replace(/[Z]+/g, m => timezone(date, m)) .replace(/X{1,3}/g, m => timezone(date, m)); const unescapedStr = formattedStr.replace(new RegExp(`${DELIM}\\d+${DELIM}`, 'g'), m => { const unescaped = escapeStack.shift(); return unescaped.length > 0 ?
🌐
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.