Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a date as
var dt=new Date();

I want to convert this format in to the dd-mm-yyyy(21-Nov-2011) I am not able to convert it.
Can anybody tell me the code how can i convert it?
Posted
Updated 27-Sep-18 2:45am
v2

Check out the following link.It will show you Different Date formates

Date Format

Example to Change Date Format :
JavaScript
<html>
<head>
<script type="text/javascript">
function GetDate()
{
var d=new Date();
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
document.write("The current Date is " + d.getDate() + " " + month[d.getMonth()] + " " + d.getYear());
}
</script>
</head>
<body  önload=GetDate()>
</body>
<html>
 
Share this answer
 
v6
Comments
Mukund Thakker 21-Nov-11 7:47am    
doesn't work
Manoj K Bhoir 21-Nov-11 9:50am    
I am providing another Code which is working properly.I hope it will solve your problem.
Have a look at datejs[^], it's a nice library that makes dealing with dates in javascript much easier

http://www.datejs.com/2007/11/27/getting-started-with-datejs/[^]

Check out the API here

http://code.google.com/p/datejs/[^]

You can then use the toString() method with a format specifier to get the format you require

Date.today().toString('d-M-yyyy') 
 
Share this answer
 
var now = new Date();
var then = now.getDate() + '-' + now.getMonth() + '-' + now.getFullYear();
alert(then);
 
Share this answer
 
the one that worked for me is

createdDate = createdDate.replace(/-/g, '/').split(".")[0];
endDate = endDate.replace(/-/g, '/').split(".")[0];

i needed to compare two dates but for that i needed to parse them into date but since internet explorer doesn't support the format
2018-09-28 05:10:00+00
so i replaced the '-' with '/' and split the millisecond part using .split and then

it easily got parsed using
Date.parse(createdDate);
Date.parse(endDate);


then i compared them if deadline comes before the create date, it worked perfectly!
 
Share this answer
 

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