Javascript Data Type How to - Date format manupulation '07-Jul-2015'








Question

We would like to know how to date format manupulation '07-Jul-2015'.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from  w  w  w.  j av a  2s . c  om-->
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sep";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
var today = new Date(); 
var dd = today.getDate(); 
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear(); 
if(dd<10){dd='0'+dd} 
if(mm<10){mm='0'+mm} 
var today = dd+'-'+mm+'-'+yyyy;
var secondToday = dd+'-'+month[mm-1]+'-'+yyyy;
document.writeln(today); //Your first format!
document.writeln('<br/>');
document.writeln(secondToday) //Your second format!

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: