Convert date to different format using date command

From Notes_Wiki

Home > Rocky Linux or CentOS > Rocky Linux 9.x > Desktop tools and applications > Convert date to different format using date command

Convert date in human-readable format to seconds since epoch (1 Jan 1970)

May databases and log files may output timestamp in seconds since 1 Jan 1970 instead of using human-readable format. In such cases convert date to seconds using:

date -d <human-readable-date> +%s

For example:

date -d '1970-01-01 00:00 UTC' +%s
date -d '2022-10-15 13:20 IST' +%s


Convert epoch time (seconds since 1 Jan 1970) to human-readable time

To convert epoch time to human readable time use:

date -d @<seconds>

For example:

date -d @1665820200


Convert timezone via date command

To change time / date from one timezone to other see Converting timezone using date command


Older article on this is at Date

Home > Rocky Linux or CentOS > Rocky Linux 9.x > Desktop tools and applications > Convert date to different format using date command