javascript - How to change date output format -


i developing system allowance in php, mysql , should calculate last date employee receive allowance. javascript calculate last date. output below code 15-7-2015. 15-07-2015.

what should change output ?

<script type="text/javascript">  function calculatelast() {    	var x = document.form1.tempoh.value; //<-----------tempoh elaun      var currentdate = new date();      currentdate.setmonth(currentdate.getmonth() + eval(x));        var day = currentdate.getdate();      var monthindex = currentdate.getmonth()+1;      var year = currentdate.getfullyear();    	document.getelementbyid('tamatelaun').value = day + "-" + monthindex + "-" + year;      //document.write(day, monthnames[monthindex], year);  }  </script>

please try this,

     <script type="text/javascript"> function calculatelast() {      var x = document.form1.tempoh.value; //<-----------tempoh elaun     var currentdate = new date();     currentdate.setmonth(currentdate.getmonth() + eval(x));      var day = currentdate.getdate();     var monthindex = ("0" + (currentdate.getmonth() + 1)).slice(-2);     var year = currentdate.getfullyear();      document.getelementbyid('tamatelaun').value = day + "-" + monthindex + "-" + year;     //document.write(day, monthnames[monthindex], year); } </script> 

Comments