繁体   English   中英

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

[英]how do you convert epoch to readable date format in javascript

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

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

                  }
},

您可以使用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;

                  }
},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM