Getting a human-readable date from Epoch to variable

Well, this is probably a very simple question; but I am just returning to the saddle with Linux.

I have a variable in which there is an Epoch time called pauseTime. I need this variable to become human readable (something like 2012-06-13 13:48:30).

I know I can just type

date -d @133986838 //just a random number there

and it will print something like that. But I need to get the variable to hold this readable date, not the era ... I keep running into errors with everything I try. Any thoughts on how I can do this?

+5
source share
1 answer

Well do this:

VARIABLENAME=$(date -d @133986838)

and then

export VARIABLENAME

or in Bash, do directly:

export VARIABLENAME=$(date -d @133986838)

If you want to format, say, in the usual ISO format:

export ISODATE=$(date -d @133986838 +"%Y-%m-%d %H:%M:%S")
# or
EPOCHDATE=133986838
export ISODATE=$(date -d @$EPOCHDATE +"%Y-%m-%d %H:%M:%S")

+ man date.

: $() - . . , $() , . , .

+7

All Articles