I am trying to convert a timestamp from d/m/yyyy
to yyyy-mm-dd
through JavaScript
. Here is my code.
var d = new Date();
d.setDate(d.getDate()-5);
temp = d.toLocaleString({minimumIntegerDigits: 2, useGrouping:false}).split(',')[0].split("/").reverse().join("-");
console.log(temp)
I am getting output like this 2016-5-5
, but what I am suppose to get is 2016-05-05
. I tried options like minimumIntegerDigits
with toLocaleString
but its not working.
Thanks in advance.