-
Notifications
You must be signed in to change notification settings - Fork 0
Date
nntrn edited this page Oct 19, 2023
·
5 revisions
def fromdateiso8601: strptime("%Y-%m-%dT%H:%M:%SZ")|mktime;
def todateiso8601: strftime("%Y-%m-%dT%H:%M:%SZ");
def fromdate: fromdateiso8601;
def todate: todateiso8601;
def duration($dt1;$dt2;$fmt):
($dt1|strptime($fmt)|strftime("%s")|tonumber) as $date1 |
($dt2|strptime($fmt)|strftime("%s")|tonumber) as $date2 |
$date2 - $date1;
def seconds_to_days($seconds): ($seconds / 86400);
def days_to_years($days): ($days / 365);
def precision($points):
. as $input | $input
| tostring
| split(".")
| [.[0], (.[1]|split("")|.[0:($points|tonumber)]|join(""))? ]
| join(".")
| tonumber;
$ jq -n now
1697714777
$ date +%X
06:37:31
$ jq -n '1697714777 | strftime("%H:%M")'
"11:37"
$ jq -n '1697714777 | strflocaltime("%H:%M")'
"06:37"
$ jq -n 'now | todate'
"2023-07-07T04:00:29Z"
$ jq -nc 'now | localtime'
[2023,6,7,18,39,34.41610598564148,5,187]
$ jq -nc 'now | gmtime'
[2023,6,7,23,40,41.17337107658386,5,187]
$ jq -n '1690267193 | strflocaltime("%F %X")'
"2023-07-25 01:39:53"
$ jq -n '1690267193 | todate'
"2023-07-25T06:39:53Z"
$ jq -c -n '"2022-09-07" | strptime("%Y-%m-%d")'
[2022,8,7,0,0,0,3,249]
$ jq -n '"2022-09-07" | strptime("%Y-%m-%d") | todateiso8601'
"2022-09-07T00:00:00Z"
$ jq -n '"2022-09-07" | strptime("%Y-%m-%d") | todate'
"2022-09-07T00:00:00Z"
$ jq -c -n '"2022-09-07" | strptime("%Y-%m-%d")'
[2022,8,7,0,0,0,3,249]
$ jq -c -n '"2022-09-07" | strptime("%Y-%m-%d") | mktime'
1662512400
$ jq 'strptime("%Y-%m-%dT%H:%M:%SZ")|mktime' <<<'"2015-03-05T23:51:47Z"'
1425599507
$ echo '"2023-07-07T04:00:29Z"' | jq -c 'strptime("%Y-%m-%dT%H:%M:%SZ")'
[2023,6,7,4,0,29,5,187]
Resources: