# How to convert between dates and seconds since the Unix Epoch in Bash

Today I learned how to convert between dates and seconds since the Unix Epoch using the date command.

# Display the current date

>>> date
Thu 10 Jun 2021 11:24:50 SAST
1
2

# Display the current date as seconds since the Unix Epoch

>>> date +%s
1623317056
1
2

# Display a given date as seconds since the Unix Epoch

>>> date --date="2021-06-01 20:00:00" +%s
1622570400
1
2

# Convert seconds since the Unix Epoch to a user-friendly date

>>> date --date='@2147483647'
Tue 19 Jan 2038 05:14:07 SAST
1
2

Newsletter

If you'd like to subscribe to my blog, please enter your details below. You can unsubscribe at any time.

Powered by Buttondown.

Last Updated: 11/20/2023, 10:04:51 AM