从数组中过滤日期范围

安娜·阿尔梅斯塔(Anna Almestal)

我正在读取一个.txt文件,该文件已拆分为包含信息行的数组。

这是我的原始.txt

|datestamp              |endpoint    |id    |
|2019-03-01 09:00:00UTC |/co.html    |12345 |
|2019-03-01 09:00:00UTC |/co.html    |12346 |
|2019-03-01 10:00:00UTC |/co.html    |12345 |
|2019-03-01 10:30:00UTC |/hello.html |12347 |
|2019-03-01 11:00:00UTC |/co.html    |12347 |
|2019-03-02 11:00:00UTC |/co.html    |12348 |
|2019-03-02 12:00:00UTC |/hello.html |12348 |
|2019-03-03 13:00:00UTC |/hello.html |12349 |

所以现在我得到了以下信息:

[
'|datestamp              |endpoint    |id    |',
'|2019-03-01 09:00:00UTC |/co.html    |12345 |',
'|2019-03-01 09:00:00UTC |/co.html    |12346 |',
'|2019-03-01 10:00:00UTC |/co.html    |12345 |',
'|2019-03-01 10:30:00UTC |/hello.html |12347 |',
'|2019-03-01 11:00:00UTC |/co.html    |12347 |',
'|2019-03-02 11:00:00UTC |/co.html    |12348 |',
'|2019-03-02 12:00:00UTC |/hello.html |12348 |',
'|2019-03-03 13:00:00UTC |/hello.html |12349 |',
''
]

所以我需要过滤说这些日期戳2019-03-01 10:00:00UTC-2019-03-02 11:00:00UTC

我需要用“ |”分割数组吗 以及在这样做之前?

我该如何解决?

等等

不,您不需要先拆分数组的元素。您可以从部分字符串中创建Date()对象,并将它们与代表开始和结束日期/时间的Date()对象进行比较:

let mydates = [
'|datestamp              |endpoint    |id    |',
'|2019-03-01 09:00:00UTC |/co.html    |12345 |',
'|2019-03-01 09:00:00UTC |/co.html    |12346 |',
'|2019-03-01 10:00:00UTC |/co.html    |12345 |',
'|2019-03-01 10:30:00UTC |/hello.html |12347 |',
'|2019-03-01 11:00:00UTC |/co.html    |12347 |',
'|2019-03-02 11:00:00UTC |/co.html    |12348 |',
'|2019-03-02 12:00:00UTC |/hello.html |12348 |',
'|2019-03-03 13:00:00UTC |/hello.html |12349 |',
''
]

let startDate = new Date("2019-03-01 10:00:00");
let endDate = new Date("2019-03-02 11:00:00");

let filtered = mydates.filter(d => new Date(d.substr(1, 19)) >= startDate && new Date(d.substr(1, 19)) <= endDate);
console.log(filtered);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

从数组中过滤日期范围

来自分类Dev

jQuery按日期范围过滤数组

来自分类Dev

如何在DataTables中过滤日期范围?

来自分类Dev

按SPARQL中的日期范围过滤

来自分类Dev

Django中的日期范围过滤器

来自分类Dev

Ruby 中的日期范围过滤器

来自分类Dev

从数组中过滤特定范围的数字

来自分类Dev

将过滤范围获取到数组中

来自分类Dev

按日期范围进行数组过滤

来自分类Dev

按日期范围过滤

来自分类Dev

Solr日期范围过滤

来自分类Dev

在浊度Lucene搜索中在日期范围过滤中搜索?

来自分类Dev

如何在Spark SQL中按日期范围过滤

来自分类Dev

为熊猫中的特定日期范围过滤数据框

来自分类Dev

如何从csv文件的特定列中过滤日期范围?

来自分类Dev

在列表中添加日期范围过滤器选项

来自分类Dev

linq to crm 中的日期范围过滤器

来自分类Dev

按 R 中的日期范围过滤 data.frame

来自分类Dev

如何按django中的日期范围过滤记录?

来自分类Dev

Laravel - 针对数据库中的日期范围的 PHP/MySQL 日期范围过滤器

来自分类Dev

如何根据reactjs中的日期范围选择(开始日期-结束日期)过滤表格行?

来自分类Dev

过滤范围日期弹性搜索

来自分类Dev

动态过滤日期范围的代码

来自分类Dev

范围滑块推到数组,过滤重复项,并在范围为0时从数组中删除

来自分类Dev

过滤或检查日期范围内的日期

来自分类Dev

通过日期范围或单词过滤器过滤Meteor.js中的集合

来自分类Dev

在数组中查找日期范围并返回最左值的公式

来自分类Dev

我如何过滤出反应表中某个日期范围之间的日期

来自分类Dev

在 Python 中无需过滤即可在日期范围内查找最大日期

Related 相关文章

热门标签

归档