I think the function toLocaleDateString use the default local data on the device.

try this code to check the output:

// America/Los_Angeles for the US
// US English uses month-day-year order
console.log(date.toLocaleDateString('en-US'));
// → "12/19/2012"

// British English uses day-month-year order
console.log(date.toLocaleDateString('en-GB'));
// → "20/12/2012"

// Korean uses year-month-day order
console.log(date.toLocaleDateString('ko-KR'));
// → "2012. 12. 20."

// Arabic in most Arabic speaking countries uses real Arabic digits
console.log(date.toLocaleDateString('ar-EG'));
// → "٢٠‏/١٢‏/٢٠١٢"

// chinese
console.log(date.toLocaleDateString('zh-Hans-CN'));
// → "2012/12/20"
Answer from lostomato on Stack Overflow
Top answer
1 of 11
92

I think the function toLocaleDateString use the default local data on the device.

try this code to check the output:

// America/Los_Angeles for the US
// US English uses month-day-year order
console.log(date.toLocaleDateString('en-US'));
// → "12/19/2012"

// British English uses day-month-year order
console.log(date.toLocaleDateString('en-GB'));
// → "20/12/2012"

// Korean uses year-month-day order
console.log(date.toLocaleDateString('ko-KR'));
// → "2012. 12. 20."

// Arabic in most Arabic speaking countries uses real Arabic digits
console.log(date.toLocaleDateString('ar-EG'));
// → "٢٠‏/١٢‏/٢٠١٢"

// chinese
console.log(date.toLocaleDateString('zh-Hans-CN'));
// → "2012/12/20"
2 of 11
76

JavaScript Date toLocaleString() This method formats a date into a string, using language specific format.

Examples :

Only date :

var n = new Date();
console.log("es-CL: " + n.toLocaleDateString("es-CL"));
// es-CL: 03-09-2021

Date with Time :

var n = new Date();
console.log("es-CL: " + n.toLocaleString("es-CL"));
// es-CL: 03-09-2021 17:56:58

List are here :

ar-SA: ٢٦‏/١‏/١٤٤٣ هـ في ٥:٥٦:٥٨ م
bn-BD: ৩/৯/২০২১ ৫:৫৬:৫৮ PM
bn-IN: ৩/৯/২০২১ ৫:৫৬:৫৮ PM
cs-CZ: 3. 9. 2021 17:56:58
da-DK: 3.9.2021 17.56.58
de-AT: 3.9.2021, 17:56:58
de-CH: 3.9.2021, 17:56:58
de-DE: 3.9.2021, 17:56:58
el-GR: 3/9/2021, 5:56:58 μ.μ.
en-AU: 03/09/2021, 5:56:58 pm
en-CA: 2021-09-03, 5:56:58 p.m.
en-GB: 03/09/2021, 17:56:58
en-IE: 3/9/2021, 17:56:58
en-IN: 3/9/2021, 5:56:58 pm
en-NZ: 3/09/2021, 5:56:58 pm
en-US: 9/3/2021, 5:56:58 PM
en-ZA: 2021/09/03, 17:56:58
es-AR: 3/9/2021 17:56:58
es-CL: 03-09-2021 17:56:58
es-CO: 3/9/2021, 5:56:58 p. m.
es-ES: 3/9/2021 17:56:58
es-MX: 3/9/2021 17:56:58
es-US: 3/9/2021 5:56:58 p. m.
fi-FI: 3.9.2021 klo 17.56.58
fr-BE: 03/09/2021, 17:56:58
fr-CA: 2021-09-03, 17 h 56 min 58 s
fr-CH: 03.09.2021, 17:56:58
fr-FR: 03/09/2021, 17:56:58
he-IL: 3.9.2021, 17:56:58
hi-IN: 3/9/2021, 5:56:58 pm
hu-HU: 2021. 09. 03. 17:56:58
id-ID: 3/9/2021 17.56.58
it-CH: 3/9/2021, 17:56:58
it-IT: 3/9/2021, 17:56:58
ja-JP: 2021/9/3 17:56:58
ko-KR: 2021. 9. 3. 오후 5:56:58
nl-BE: 3/9/2021 17:56:58
nl-NL: 3-9-2021 17:56:58
no-NO: 3.9.2021, 17:56:58
pl-PL: 3.09.2021, 17:56:58
pt-BR: 03/09/2021 17:56:58
pt-PT: 03/09/2021, 17:56:58
ro-RO: 03.09.2021, 17:56:58
ru-RU: 03.09.2021, 17:56:58
sk-SK: 3. 9. 2021, 17:56:58
sv-SE: 2021-09-03 17:56:58
ta-IN: 3/9/2021, பிற்பகல் 5:56:58
ta-LK: 3/9/2021, 17:56:58
th-TH: 3/9/2564 17:56:58
tr-TR: 03.09.2021 17:56:58
zh-CN: 2021/9/3 下午5:56:58
zh-HK: 3/9/2021 下午5:56:58
zh-TW: 2021/9/3 下午5:56:58
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleDateString
Date.prototype.toLocaleDateString() - JavaScript | MDN
The toLocaleDateString() method of Date instances returns a string with a language-sensitive representation of the date portion of this date in the local timezone. In implementations with Intl.DateTimeFormat API support, this method delegates to Intl.DateTimeFormat.
🌐
GitHub
gist.github.com › noromanba › 6737784
format current local date to "yyyy-MM-dd HH:mm:ss TZ-info" on X-browser · GitHub
format current local date to "yyyy-MM-dd HH:mm:ss TZ-info" on X-browser - toDateTimeTZInfoString.js
🌐
Substack
patrickojeh.substack.com › p › a-guide-to-formatting-dates-with
A Guide to Formatting Dates with toLocaleDateString in JavaScript
January 10, 2025 - The first parameter of toLocaleDateString() is the locale string — which would be en-US for American English, en-GB for British English, or ja-JP for Japanese. const ISOString = '2025-01-15T10:00:00Z'; const date = new Date(ISOString); // US format (MM/DD/YYYY) console.log(date.toLocaleDateString('en-US')); // Output: "1/15/2025" // British format (DD/MM/YYYY) console.log(date.toLocaleDateString('en-GB')); // Output: "15/01/2025" // Japanese format (YYYY/MM/DD) console.log(date.toLocaleDateString('ja-JP')); // Output: "2025/01/15"
🌐
MSR
rajamsr.com › home › javascript date format yyyy-mm-dd: easy way to format
Javascript Date Format YYYY-MM-DD: Easy Way to Format | MSR - Web Dev Simplified
March 3, 2024 - In addition to this, we explored how to format dates with the time yyyy-mm-dd hh:mm:ss format and the mm/dd/yyyy format. To format dates in a specific locale, you have to use the toLocaleDateString() method with custom options.
🌐
W3Schools
w3schools.com › jsref › jsref_tolocaledatestring.asp
JavaScript Date toLocaleDateString() Method
new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function
🌐
LogRocket
blog.logrocket.com › home › how to format dates in javascript: methods, libraries, and best practices
How to format dates in JavaScript: Methods, libraries, and best practices - LogRocket Blog
May 8, 2025 - // Test with 100,000 operations const COUNT = 100000; // Native JS console.time('Native'); for (let i = 0; i < COUNT; i++) { new Date().toISOString(); } console.timeEnd('Native'); // Typically fastest // date-fns console.time('date-fns'); for (let i = 0; i < COUNT; i++) { format(new Date(), 'yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\''); } console.timeEnd('date-fns'); // Close second // Day.js console.time('Day.js'); for (let i = 0; i < COUNT; i++) { dayjs().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); } console.timeEnd('Day.js'); // Usually faster than Moment // Moment.js console.time('Moment'); for (let i = 0; i < COUNT; i++) { moment().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); } console.timeEnd('Moment'); // Usually slowest
Find elsewhere
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
const date = new Date(); // British English uses day-month-year order console.log(date.toLocaleDateString('en-GB')); // 24/04/2023 // US English uses month-day-year order console.log(date.toLocaleDateString("en-US")); // 04/24/2023 · You can use the getDate(), getMonth() and getFullYear() methods to get the day, month and year of the date, and then concatenate them with slashes. You may need to add a leading zero to the day and month digits if they are less than 10. For example: const today = new Date(); const yyyy = today.getFullYear(); let mm = today.getMonth() + 1; // month is zero-based let dd = today.getDate(); if (dd < 10) dd = '0' + dd; if (mm < 10) mm = '0' + mm; const formatted = dd + '/' + mm + '/' + yyyy; console.log(formatted); // 24/04/2023
🌐
GitHub
github.com › grafana › k6 › issues › 3731
Incorrect date format returned with Date.toLocaleDateString() · Issue #3731 · grafana/k6
May 3, 2024 - Brief summary The js function Date().toLocaleDateString() always returns MM/DD/YYYY regardless of localization string. k6 version V0.50 and v0.49 OS Windows 10 Pro Version 22H2 OS build 19045.4291 Docker version and image (if applicable)...
Published   May 03, 2024
🌐
Linangdata
linangdata.com › snippets-of-javascript › format-date
How to format a JavaScript date?
July 13, 2022 - Format gives you a lot of flexibility in formatting dates. For example to get a date in teh format January 1, 2022 we'll use the format string "MMMM d, YYYY". DD: Day of the month, zero-padded: 01 ·
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-format-date-in-typescript
How to Format Date in TypeScript ? - GeeksforGeeks
August 1, 2024 - The toLocaleDateString method allows us to customize the date format by specifying options such as the year, month and day.
🌐
Medium
habtesoft.medium.com › 8-ways-of-date-formatting-in-javascript-1380625a1f50
8 Ways of Date Formatting in Javascript | by habtesoft | Medium
October 18, 2024 - const date = new Date(); // Default locale (browser's locale) console.log(date.toLocaleDateString()); // e.g., "9/20/2024" // Custom locale console.log(date.toLocaleDateString('en-GB')); // "20/09/2024" (dd/mm/yyyy) console.log(date.toLocaleDateString('en-US')); // "09/20/2024" (mm/dd/yyyy) console.log(date.toLocaleDateString('ja-JP')); // "2024/09/20" (yyyy/mm/dd) // Custom options console.log(date.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })); // "Friday, September 20, 2024"
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;
}