Here the author writes:
Would it also parse ISO timestamps like
2015-03-05T19:40:53.324Z? Eg. what you get from javascriptnew Date().toISOString().
https://github.com/stedolan/jq/issues/364#issuecomment-77442886
What we need is
strptime("%Y-%m-%dT%H:%M:%S.%fZ")
similar to how python does it.
is progress in https://github.com/stedolan/jq/pull/1413#issuecomment-351315539 kind of abandoned?
hi @juliangamble
jq-1.6 had supports strptime usage.you can try it
root@oss-001:test_jq# echo '"2015-03-05T23:51:47Z"' | jq 'strptime("%Y-%m-%dT%H:%M:%SZ")'
[
2015,
2,
5,
23,
51,
47,
4,
63
]
You can see detailed usage in the manual or jq-1.6 manual.yml.
https://github.com/stedolan/jq/blob/master/docs/content/manual/v1.6/manual.yml
I think this is an issue about %f support which jq-1.6 does not support.
% echo '"2015-03-05T23:51:47.487Z"' | jq 'strptime("%Y-%m-%dT%H:%M:%S.%fZ")'
jq: error (at <stdin>:1): date "2015-03-05T23:51:47.487Z" does not match format "%Y-%m-%dT%H:%M:%S.%fZ"
% python -c 'from datetime import datetime; print(datetime.strptime("2015-03-05T23:51:47.487Z", "%Y-%m-%dT%H:%M:%S.%fZ"))'
2015-03-05 23:51:47.487000
Struggled today with this, problem is that the unix "strptime" doesn't support milliseconds. As such, I switched to using a regex replace
.last_updated |= sub("(?<time>.*)\\..*Z"; "\(.time)Z")
So I'm transforming this "2015-03-05T23:51:47.487Z" to "2015-03-05T23:51:47Z"
Most helpful comment
I think this is an issue about
%fsupport which jq-1.6 does not support.