Skip to content

Convert epoch time to human-readable time in Terminal

This is a stupid-simple Unix tip, posting more as a reminder to myself than anything truly insightful—I keep forgetting these details, so by doing the work to create a post about it, I'll never forget them again…

I've been using unix time from the unix side of macOS quite a bit lately, as it's an easy way to get timestamps for things. Getting the epoch time is easy:

$ date +%s
1641735529

The thing I always forget is how to convert an epoch time back into a human-readable format of my choosing, despite it being shown in the man page. It's simple; use the -r option, like this:

$ date -r 1641735529
Sun Jan  9 05:38:49 PST 2022

And, of course, you can format it how you like using a strftime formatted format string, i.e.

$ date -r 1641735529 "+Today is %A, %B %e, and it's %I:%M:%S %p"
Today is Sunday, January  9, and it's 05:38:49 AM

Related: Yes, I wake up early; it started with macosxhints.com and needing to update the site before I left for my real job each day, and it persists 20 odd years later.