Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I written code as follows



document.write(new Date().toLocaleDateString());




When i run the above code shows output as follows

1/23/2018


i want to change above date format as 23/1/2018.

for that i changed the above code as document.write(new Date().toLocaleDateString(dd/mm/yyyy));

But the above code it is not working

What I have tried:

I written code as follows



document.write(new Date().toLocaleDateString());




When i run the above code shows output as follows

1/23/2018


i want to change above date format as 23/1/2018.

for that i changed the above code as document.write(new Date().toLocaleDateString(dd/mm/yyyy));

But the above code it is not working
Posted
Updated 17-Oct-18 22:34pm

try

var dt = new Date();
  var mm = dt.getMonth() + 1;
  var dd = dt.getDate();
  var yyyy = dt.getFullYear();
  var format = dd + '/' + mm + '/' + yyyy
  document.write(format);
 
Share this answer
 
Comments
[no name] 23-Jan-18 5:47am    
Thanks it is working fine
Karthik_Mahalingam 23-Jan-18 5:51am    
welcome
try this:

document.write(new Date().toLocaleDateString('en-GB'));

output has to be: 23/01/2018
 
Share this answer
 
v2
Comments
Richard Deeming 18-Oct-18 10:11am    
Worth pointing out that this won't work in IE10 or earlier. Support for the locales property was added in IE11.
toLocaleString: Browser Compatibility[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900