It is easy to use
var timestamp = 1463568871; var date = new Date(timestamp * 1000); var day = date.getDate(); var month = date.getMonth() + 1; var year = date.getFullYear(); var formatted = year + "-" + month + "-" + day ; alert(formatted);
Use timestamp in milliseconds to create
getDate() to get day in month. Use
getMonth() to get month in year. But 0 means January, 1 means February and so on. When we get month we need add 1. Use
getFullYear to get the year. After getting them you can format the date as you like.