Kunok Kunok - 6 months ago 53
Javascript Question

Convert systematic date to formatted date

I want to convert systematic date into readable date format. However when I pass systematic date as argument to date constructor I get

Invalid date
response. How to do this properly in order to display formatted date such as
for GMT+2 ?

var date = message.date; // => 1466663308000
var dateObject = new Date(date);

Console output:

Invalid Date


You have to make sure the timestamp value is a number and not a string:

    var date = message.date; 
    var dateObject = new Date(+date); // note the +

Once you've got a valid date, there are many other questions here about formatting dates.