Here is very simple example how you can handle this situation.
var mydate = new Date();_x000D_
_x000D_
var month = (mydate.getMonth().toString().length < 2 ? "0"+mydate.getMonth().toString() :mydate.getMonth());_x000D_
_x000D_
var date = (mydate.getDate().toString().length < 2 ? "0"+mydate.getDate().toString() :mydate.getDate());_x000D_
_x000D_
var year = mydate.getFullYear();_x000D_
_x000D_
console.log("Format Y-m-d : ",year+"-"+month+"-" + date);_x000D_
_x000D_
console.log("Format Y/m/d : ",year+"/"+month+"/" + date);
_x000D_