Convert Epoch Time to Human Readable Format (Prefer PST)

I regularly need to convert unix (epoch) time to human readable. I would love if there was a macro or action that could do this for me. Currently, I use an online converter:

Is there some way KM can convert epoch time to PST?

Yes, you should be able to use the ICUDateTimeFor token for this. If you're in the PST time zone yourself, you can also use the GMTOFFSET() function with it to get human readable PST time. See the Dates and Times page on the KM wiki for more information.

Thanks, gglick.

Unfortunately, since I don't code this is quite over my head. Any chance you are very bored and could step by step it for me?

Oh, nevermind. Just figured out how to do it in bash. Thanks again!

date -r <insert_epoch_time>

If the output of

date -r 1582217052


Thu Feb 20 17:44:12 CET 2020

then this should be the equivalent KM-ICU expression:

%ICUDateTimeFor%1582217052%EEE MMM dd HH:mm:ss z yyyy%

[demo] Convert Given Epoch Time to a Different Format.kmmacros (3.2 KB)

Thanks, Tom. Just saw Dark Star Orchestra, Friday in Ventura. Epic.

1 Like

Hi @Tom! I went to revisit this, as the need came up again, to convert Ep times repeatedly.

I noticed that the output from the macro does not match the output when I use

Example: EP time 1613740332121 is converted to GMT : Friday, February 19, 2021 1:12:12.121 PM -when using the website.

But the output of the macro is: Thu Feb 20 08:44:12 PST 2020

Is this an issue with time zone? Thanks for looking, Tom. I really appreciate it!

Hey @Ihventura_Hutch,

Tom hasn't been around for months, so it's unlikely he'll respond.

Something is definitely strange here.

GMT:    Fri Feb 19 13:12:12.121  GMT 2021
Chris:  Fri Feb 19 07:12:12		 CST 2021
Hutch:  Thu Feb 20 08:44:12 	 PST 2020

By my reckoning you should see (if your timezone is actually PST):

Hutch:  Thu Feb 19 05:44:12 	 PST 2020


Probably I’m missing the real issue (I’m a bit out of KM practice), but for my time zone the KM expression gives the same result as

In KM (without the milliseconds)…

%ICUDateTimeFor%1613740332%EEE MMM dd HH:mm:ss z yyyy%

…returns: Fri Feb 19 14:12:12 CET 2021.

(CET is GMT+01)

PS: I’m still on KM 9.2

I was creating a macro that got the modification date for a file, and it comes in as the Unix epoch time (localized for my time zone). That's great, I understand epoch time and why it's used, etc.

I thought it'd be trivial to convert that epoch time to some readable format in KM. But no (at least not for me); after 30 minutes of frustration, here's what I wound up doing:

Execute shell script to variable:

$datestring = localtime($ENV{KMVAR_UnixTime});
print $datestring;

This worked great, and I was on my way. But what's the right way to do it, when the time value is stored in a variable? I'm pretty sure I should be using ICUDateTimeFor, but I could not make anything work. I know you can't reference (easily, at least) a variable in the token, so how am I supposed to be doing this?


Hey Rob,

%ICUDateTimeFor%[unixtime]%[output date format]%

token:ICUDateTime [Keyboard Maestro Wiki]

Here's the basic method.

Epoch Time To Human Readable Format v1.00.kmmacros (6.0 KB)


Keyboard Maestro Export

What's your source time zone?


1 Like

Source time zone is Pacific. Yea, that works. I just couldn't make it work earlier, no idea why. Still, I might switch my perl script out for the bash version above—super simple, and it's already adjusted for the local time zone.


1 Like

Thanks so much for this. There are a few steps that I can't figure out. How would I add the human readable format to the beginning of a selection of the epoch filenames in Finder?

Hey Ron,

This is kind of vague. Please provide a real-world example of what your Finder-selection looks like and what the output is supposed to look like.