If you want the current time as the number of seconds since the epoch:
x=$(date +%s)
With zsh
after zmodload zsh/datetime
, or with recent versions of bash
, you can also do x=$EPOCHSECONDS
.
x=$(date -u)
stores something like Tue 01 Nov 2022 10:58:08 AM UTC
or mar. 01 nov. 2022 12:05:48 UTC
or 2022年 11月 01日 星期二 12:06:04 UTC
depending on the user's locale with variation between systems as well into $x
.
Getting the corresponding epoch seconds for that date is going to be difficult.
In the case of Tue 01 Nov 2022 10:58:08 AM UTC
, if you have access to the GNU implementation of date
, you're in luck as that's one of the date formats that it recognises with its -d
option.
So:
epoch=$(date -d "$x" +%s)
Will work there. Your date
command seems not to be the GNU one, but GNU date
might be available as gdate
or /opt/gnu/bin/date
...