问题描述
在处理日期时间转换时,我遇到了这个问题。我有来自postgreSQL数据库的时间戳数据,格式如下所示:2011-04-04 19:27:39.92034 b
$ b
为了以高图形显示它,我必须将它转换为日期或时间对象。如果没有毫秒,我可以使用轻松转换它。
这个问题的解决方案?谢谢
new Date(2011-04-04 19:27:39.92034)。getTime()
1301941659920
I got this problem when dealing with date time conversion. I have timestamp data from postgreSQL database with format like this one
"2011-04-04 19:27:39.92034"
In order to display it in highcharts, I have to convert it to date or time object. Without milliseconds, I easily convert it with Date.js
But milliseconds can't be handled with that library. I tried also with Date.parse but always got NaN.
Any solution for this problem? Thank you
JS built in Date class should be able to handle this, and getTime() can return milliseconds since start 1970 (UNIX time). Watch out for time zone issues though; the constructor may interpret the date/time as being local, but getTime()'s milliseconds since 1970 may be in UTC, baking in a conversion that is difficult to remove.
new Date("2011-04-04 19:27:39.92034").getTime()
1301941659920
这篇关于从毫秒数字转换为日期对象Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!