$ echo '{}' | jq 'now'
1506504885.298058
$ echo '{}' | jq 'now | gmtime '
[
2017,
8,
27,
9,
34,
47.25080108642578,
3,
269
]
$ echo '{}' | jq 'now | gmtime | todate'
"2017-09-27T09:35:00Z"
$ echo '{}' | jq 'now | gmtime | todate[:10]'
"2017-09-27"
$ echo '{}' | jq 'now | todate[:10]'
"2017-09-27"
得到三天前的時間:
$ echo '{}' | jq '(now - 86400*3) | gmtime | todate[:10]'
"2017-09-24"
假想一票資料:
$ echo '[{"StartTime": "2017-09-21T10:32:33.000Z"},{"StartTime": "2017-09-22T10:32:33.000Z"},{"StartTime": "2017-09-26T10:32:33.000Z"},{"StartTime": "2017-09-24T10:32:33.000Z"},{"StartTime": "2017-09-25T10:32:33.000Z"},{"StartTime": "2017-09-19T10:32:33.000Z"},{"StartTime": "2017-09-01T10:32:33.000Z"},{"StartTime": "2017-09-92T10:32:33.000Z"}]' | jq ''
[
{
"StartTime": "2017-09-21T10:32:33.000Z"
},
{
"StartTime": "2017-09-22T10:32:33.000Z"
},
{
"StartTime": "2017-09-26T10:32:33.000Z"
},
{
"StartTime": "2017-09-24T10:32:33.000Z"
},
{
"StartTime": "2017-09-25T10:32:33.000Z"
},
{
"StartTime": "2017-09-19T10:32:33.000Z"
},
{
"StartTime": "2017-09-01T10:32:33.000Z"
},
{
"StartTime": "2017-09-92T10:32:33.000Z"
}
]
挑出超過七天者(此乃字串比對):
$ echo '[{"StartTime": "2017-09-21T10:32:33.000Z"},{"StartTime": "2017-09-22T10:32:33.000Z"},{"StartTime": "2017-09-26T10:32:33.000Z"},{"StartTime": "2017-09-24T10:32:33.000Z"},{"StartTime": "2017-09-25T10:32:33.000Z"},{"StartTime": "2017-09-19T10:32:33.000Z"},{"StartTime": "2017-09-01T10:32:33.000Z"},{"StartTime": "2017-09-92T10:32:33.000Z"}]' | jq '.[] | if (.StartTime[0:10] < (now - (86400* 7) | todate[0:10]) ) then .StartTime else empty end '
"2017-09-19T10:32:33.000Z"
"2017-09-01T10:32:33.000Z"
沒有留言:
張貼留言