對象數組我已經基於每個小時逐組合的對象的陣列。例如:
分離基於小時逐從時間戳屬性
[{"id": "12345", "data": "abc", "timestamp": "2017-10-17T00:05:30.523Z"},
{"id": "16375", "data": "sgr", "timestamp": "2017-10-17T00:23:54.234Z"},
{"id": "46537", "data": "etd", "timestamp": "2017-10-17T01:36:16.463Z"},
{"id": "83645", "data": "eth", "timestamp": "2017-10-17T01:32:25.640Z"},
{"id": "36153", "data": "her", "timestamp": "2017-10-17T01:56:13.478Z"},
{"id": "31383", "data": "sry", "timestamp": "2017-10-17T05:56:56.362Z"},
{"id": "68123", "data": "rya", "timestamp": "2017-10-17T06:34:30.652Z"}]
我要在以下格式的數據結果:
{ "00:00-00:59":
[{"id": "12345", "data": "abc", "timestamp": "2017-10-17T00:05:30.523Z"},
{"id": "16375", "data": "sgr", "timestamp": "2017-10-17T00:23:54.234Z"}]
"01:00-01:59":
[{"id": "46537", "data": "etd", "timestamp": "2017-10-17T01:36:16.463Z"},
{"id": "83645", "data": "eth", "timestamp": "2017-10-17T01:32:25.640Z"},
{"id": "36153", "data": "her", "timestamp": "2017-10-17T01:56:13.478Z"}]
"05:00-05:59": [{"id": "31383", "data": "sry", "timestamp": "2017-10-17T05:56:56.362Z"}]
"06:00-06:59": [{"id": "68123", "data": "rya", "timestamp": "2017-10-17T06:34:30.652Z"}]
是否有可能如上面提到的數據格式?我如何爲需求編寫短代碼?
它的工作原理,只需在日期構造函數後面查看是否有效日期。 – gurvinder372
@ Firemen26非常感謝。工作得很好 – Chetanraj
哇。這太棒了! – levi