【问题标题】:Convert date/time into timestamp将日期/时间转换为时间戳
【发布时间】:2017-06-08 10:06:38
【问题描述】:

我想将以下日期和时间转换为 13 位时间戳。注意我使用严格模式。

日期:

2017 年 6 月 1 日星期四 00:00:00 GMT+0200 (CEST)

时间: 03:00

我尝试使用 Date.parse() 但它不起作用。最好的方法是什么?

【问题讨论】:

  • 你想要纪元时间戳吗??

标签: javascript angular


【解决方案1】:

你可以使用getTime函数:

console.log(new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)').getTime());

【讨论】:

    【解决方案2】:

    试试下面的代码

    console.log(new Date().getTime());

    【讨论】:

      【解决方案3】:

      创建日期对象,根据需要添加时间,然后使用getTime() 函数:

      "use strict";
      var date = new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)');
      date.setHours(parseInt('03'),[parseInt('00')]); //apply hours and minutes
      console.log(date.toString());
      console.log(date.getTime()); //use of getTime()

      【讨论】:

        【解决方案4】:
        console.log(+new Date("Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)"))
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-04-25
          • 2022-01-08
          • 2020-10-19
          • 2016-11-26
          • 1970-01-01
          相关资源
          最近更新 更多