Linux Commands

How to Convert a Linux Epoch Timestamp to Date on the Command Line

Epoch timestamp is the time passed since January 1, 1970 at 00:00:00 UTC in seconds. These timestamps are commonly used in computing and are particularly useful for dealing with dates and times in a standard and consistent manner. Reading and interpreting these timestamps can be difficult for people who are unfamiliar with epoch timestamps. Please read this guide if you also want to know how to convert a Linux epoch timestamp to date on the command line.

How to Convert a Linux Epoch Timestamp to Date on the Command Line

The date command is a standard Unix utility that displays and manipulates the dates and times. It is the pre-installed utility in most Linux distributions and can convert an epoch timestamp to a human-readable date and time. Run the following command to convert an epoch timestamp:

date -d @<timestamp>

In the previous command, you can replace the as the number of seconds since January 1, 1970 at 00:00:00 UTC.

For example, to convert the epoch timestamp 1674000000 which corresponds to January 18, 2023 at 00:00:00 GMT, use the following command:

date -d @1674000000

The -d option specifies the date and time in a format that is understood by the date command. The “@” symbol indicates that the argument is an epoch timestamp instead of a different time format.

The date command supports several different output formats which you can specify using the + option and a format string. For example, to display the date and time in the YYYY-MM-DD HH:MM:SS format, use the following command:

date -d @1674000000 +%Y-%m-%d:%H:%M:%S

You can find more information on the format codes on the manual date page (man date).

Conclusion

This is all about the simple way to convert a Linux epoch timestamp to date on the command line. This can be useful for converting timestamps in log files, database entries, and other data sources into an easier-to-read and understandable format. With a simple command line argument, you can quickly and easily convert an epoch timestamp into a date and time that is usable for your purposes.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.