你如何在javascript中将纪元转换为可读日期格式

时间:2013-06-10 18:48:51

标签: javascript highcharts

我正在使用highcharts构建图表。 xaxis上的值是epoch格式。当我试图展示价值时,它会成为时代。我将如何在javascript中将其转换为可读格式。这就是我所拥有的:

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

                  }
},

1 个答案:

答案 0 :(得分:4)

您可以使用Highcharts.dateFormat功能。请注意,您必须将您的纪元数乘以1000,因为Highcharts.dateFormat需要一个JavaScript日期时间戳(自1970年1月1日以来的毫秒数)。

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

                  }
},