【问题标题】:how can I change the counting time to unix time stamp?如何将计数时间更改为 unix 时间戳?
【发布时间】:2020-04-20 21:53:42
【问题描述】:

我想获取网页产品的过期时间,并使用 javascript 日期方法将其更改为 unix 时间....

  var expiration = document.querySelector('span#bigDealTimer1');
  //with this selector I can get the time-counter.

  expiration = expiration && expiration.innerText;


如何将 span 中的过期时间更改为 unix Time ? (时间减少到零)

【问题讨论】:

标签: javascript html css-selectors


【解决方案1】:

虽然我不知道日期/时间将采用哪种格式,但您可以使用标准 Date 库将字符串日期值解析为 UNIX 时间戳。

const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');

参考 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2011-03-27
    • 2013-04-07
    相关资源
    最近更新 更多