Kunok Kunok - 1 year ago 109
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download