yank yank - 7 months ago 8
Javascript Question

How to convert date format using javascript

I am very new to javascript, how to convert date format('2016/5/6') to ('06.05.2015'). I want to convert in it because i need to manipulate date. But only ('06.05.2015') format are used everywhere.


Please suggest me any link or tutorial

Thanks

Answer
var today = new Date('2016/5/6');
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
} 

today = mm+'.'+dd+'.'+yyyy;
alert(today);

JsFiddle

Comments