Javascript从/ Date获取日期(1518696376959)/

时间:2018-02-21 06:18:28

标签: javascript

如何在javascript中从此/Date(1518696376959)/获取日期时间? 我试过这样的

var d = new Date("1519192874994");

1 个答案:

答案 0 :(得分:1)

  

我试过这样的var d = new Date(“1519192874994”);

无需将其包装在引号中Date构造函数将采用毫秒值(Number

var d = new Date(1519192874994) //Wed Feb 21 2018 11:31:14 GMT+0530 (India Standard Time)

来自"/Date(1518696376959)/"

成功

var str = "/Date(1518696376959)/";
var date = new Date( +str.match(/\d+/g)[0]  ); //notice the unary plus after getting the match