user1471980
user1471980

Reputation: 10636

how do you convert epoch to readable date format in javascript

I am building a chart using highcharts. Values on xaxis are epoch format. When I try to show the values, it comes up as epoch. How would I convert to this to readable format in javascript. This is what I have:

tooltip: {
    enabled: true,
    formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                this.x +': '+ this.y;

                  }
},

Upvotes: 1

Views: 2954

Answers (1)

Andreas K&#246;berle
Andreas K&#246;berle

Reputation: 110922

You can use the Highcharts.dateFormat function. Note you have to multiply your epoch number with 1000, as Highcharts.dateFormat needs a JavaScript date timestamp (milliseconds since Jan 1st 1970).

tooltip: {
    enabled: true,
    formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                Highcharts.dateFormat('%d.%m.%Y', this.x*1000) +': '+ this.y;

                  }
},

Upvotes: 4

Related Questions