In Linux/UNIX, you can use the date
command to convert epoch seconds to the current time.
Here’s an example:
# Set epoch seconds to a variable
epoch_seconds="1632718301"
# Use the date command to convert epoch seconds to human-readable time
formatted_time=$(date -d @$epoch_seconds)
echo "Epoch seconds: $epoch_seconds"
echo "Formatted time: $formatted_time"
In this example, we set the epoch_seconds
variable to 1632718301
. We then use the date
command with the -d
option to convert the epoch seconds to human-readable time. The @
symbol tells the date
command that the argument is in epoch seconds. The output of the date
command is stored in the formatted_time
variable.
When you run the script, the output should be similar to this:
Epoch seconds: 1632718301
Formatted time: Tue Sep 27 09:05:01 EDT 2022
The date
command can also be used to format the output in a different way, such as a different timezone or a different date format. You can refer to the date
command’s manual page for more information on its options and capabilities.