How can I convert a date in Epoch to "Y-m-d H:i:s" in Javascript?

var timestamp = 1293683278;
var date = new Date(timestamp * 1000);

var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();

console.log(year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds);

See js Date docs for further details

Another way:

var timestamp = 1293683278;
var date = new Date(timestamp * 1000);
var iso = date.toISOString().match(/(\d{4}\-\d{2}\-\d{2})T(\d{2}:\d{2}:\d{2})/)

console.log(iso[1] + ' ' + iso[2]);


You can use moment.js for this.

moment.unix(1293683278).format('YYYY-MM-DD HH:mm:ss');