JavaScript-将Date()转换为秒 [英] JavaScript - Converting a Date() into seconds

查看:108
本文介绍了JavaScript-将Date()转换为秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Algolia的此处的Hacker News API:

I'm using the Hacker News API made at Algolia here:

https://hn.algolia.com/api

我有点困惑,因为它说从某个特定的日期开始搜索帖子它说运行以下查询的时间:

I'm a bit confused as it says to search for posts since a certain time it says to run the following query:

自时间戳记 X 后的注释(秒)
http://hn.algolia.com/api/v1/search_by_date?tags=comment&numericFilters=created_at_i>X

Comments since timestamp X (in second) http://hn.algolia.com/api/v1/search_by_date?tags=comment&numericFilters=created_at_i>X

它说以秒为单位的时间戳替换 X ,但是您将如何做到这一点呢?假设我最近发表的帖子是 2015-08-25T15:35:58.000Z 。自该日期以来,我将如何精确地运行此查询来搜索帖子?我不知道如何将此日期转换为秒...

It says to replace X with a timestamp in seconds, but how exactly would you do this? Let's say the last post I have is at 2015-08-25T15:35:58.000Z. How exactly would I run this query to search for posts since that date? I don't know how to convert this date to seconds...

预先感谢!

推荐答案

getTime()将获取以毫秒为单位的日期,因此除以1000:

getTime() will get the date in milliseconds, so divide by 1000:

var date = new Date("2015-08-25T15:35:58.000Z");
var seconds = date.getTime() / 1000; //1440516958

这篇关于JavaScript-将Date()转换为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆