【问题标题】:How to filter json data with data range (React JS)如何过滤带有数据范围的 json 数据(React JS)
【发布时间】:2021-06-08 14:31:53
【问题描述】:

我有带有 ISO 日期的 JSON 数据,我想获取“date_created”在日期范围内的所有数据,无论时间是什么,并且不修改 JSON 数据的值。

日期范围示例: 开始日期:2021-05-25T16:00:00.000Z, 结束日期:2021-05-28T16:00:00.000Z

JSON 数据示例:

{
            "article_title": null,
            "article_source_url": "ttgindia.travel",
            "article_authors": null,
            "article_sections": [],
            "article_publish_date": null,
            "article_content": null,
            "article_images": null,
            "article_videos": null,
            "article_media_type": "Web",
            "article_ad_value": 0,
            "article_pr_value": 0,
            "article_language": "en",
            "article_status": "Error",
            "article_error_status": "No content",
            "article_source_from": "NodeJS Static Scraper",
            "created_by": "System",
            "updated_by": "Python Global Scraper",
            "is_in_mysql": false,
            "_id": "60ade881da0fa204f1729e79",
            "section": "5f2d7fd8591132886d070d10",
            "article_url": "http://www.ttgindia.travel/2019/04/29/advertise-with-us",
            "date_created": "2021-05-28T02:20:45.856Z",
            "date_updated": "2021-05-27T06:30:45.856Z",
            "__v": 0
        },
        {
            "article_title": null,
            "article_source_url": "ttgindia.travel",
            "article_authors": null,
            "article_sections": [],
            "article_publish_date": null,
            "article_content": null,
            "article_images": null,
            "article_videos": null,
            "article_media_type": "Web",
            "article_ad_value": 0,
            "article_pr_value": 0,
            "article_language": "en",
            "article_status": "Done",
            "article_error_status": "No content",
            "article_source_from": "NodeJS Static Scraper",
            "created_by": "System",
            "updated_by": "Python Global Scraper",
            "is_in_mysql": false,
            "_id": "60ade881da0fa204f1729e79",
            "section": "5f2d7fd8591132886d070d10",
            "article_url": "http://www.ttgindia.travel/2019/04/29/advertise-with-us",
            "date_created": "2021-05-27T07:20:45.856Z",
            "date_updated": "2021-05-27T06:30:45.856Z",
            "__v": 0
        },
        {
            "article_title": null,
            "article_source_url": "ttgindia.travel",
            "article_authors": null,
            "article_sections": [],
            "article_publish_date": null,
            "article_content": null,
            "article_images": null,
            "article_videos": null,
            "article_media_type": "Web",
            "article_ad_value": 0,
            "article_pr_value": 0,
            "article_language": "en",
            "article_status": "Error",
            "article_error_status": "No content",
            "article_source_from": "NodeJS Static Scraper",
            "created_by": "System",
            "updated_by": "Python Global Scraper",
            "is_in_mysql": false,
            "_id": "60ade881da0fa204f1729e79",
            "section": "5f2d7fd8591132886d070d10",
            "article_url": "http://www.ttgindia.travel/2019/04/29/advertise-with-us",
            "date_created": "2021-05-27T07:20:45.856Z",
            "date_updated": "2021-05-27T06:30:45.856Z",
            "__v": 0
        },
        {
            "article_title": null,
            "article_source_url": "ttgindia.travel",
            "article_authors": null,
            "article_sections": [],
            "article_publish_date": null,
            "article_content": null,
            "article_images": null,
            "article_videos": null,
            "article_media_type": "Web",
            "article_ad_value": 0,
            "article_pr_value": 0,
            "article_language": "en",
            "article_status": "Error",
            "article_error_status": "No content",
            "article_source_from": "NodeJS Static Scraper",
            "created_by": "System",
            "updated_by": "Python Global Scraper",
            "is_in_mysql": false,
            "_id": "60ade881da0fa204f1729e79",
            "section": "5f2d7fd8591132886d070d10",
            "article_url": "http://www.ttgindia.travel/2019/04/29/advertise-with-us",
            "date_created": "2021-05-27T06:30:45.856Z",
            "date_updated": "2021-05-27T06:30:45.856Z",
            "__v": 0
        },
        {
            "article_title": null,
            "article_source_url": "ttgindia.travel",
            "article_authors": null,
            "article_sections": [],
            "article_publish_date": null,
            "article_content": null,
            "article_images": null,
            "article_videos": null,
            "article_media_type": "Web",
            "article_ad_value": 0,
            "article_pr_value": 0,
            "article_language": "en",
            "article_status": "Error",
            "article_error_status": "No content",
            "article_source_from": "NodeJS Static Scraper",
            "created_by": "System",
            "updated_by": "Python Global Scraper",
            "is_in_mysql": false,
            "_id": "60ade881da0fa204f1729e79",
            "section": "5f2d7fd8591132886d070d10",
            "article_url": "http://www.ttgindia.travel/2019/04/29/advertise-with-us",
            "date_created": "2021-05-26T06:19:45.856Z",
            "date_updated": "2021-05-26T06:20:59.828Z",
            "__v": 0
        }

提前致谢!!

【问题讨论】:

    标签: javascript json reactjs


    【解决方案1】:

    假设data变量保存了所有数据

    data.filter(item => new Date(item.date_created).getTime() > new Date(start_date).getTime() && new Date(item.date_created).getTime() < new Date(end_date).getTime())
    

    【讨论】:

      猜你喜欢
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-31
      • 2014-07-19
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2020-11-14
      相关资源
      最近更新 更多