Decoding Unix Timestamps

Working with Stripe means dealing with Unix timestamps: the ones represented as seconds from Jan 1st 1970. I've been relying on various websites to convert them into something I can understand, which involved a lot of clicking around the browser, not to mention dealing with ads. I also wanted something that'll work without requiring launching or switching apps, since I'm usually looking at timestamps while trying to work on something else.

So one day I finally got around to writing a macro to do this. Here it is in full:

The JavaScript portion is as follows:

'use scrict';
(function() {
  let app = Application.currentApplication()
  app.includeStandardAdditions = true;

  let text = app.theClipboard();
  let unixTimestamp = parseInt(text);

  let date = new Date(parseInt(text) * 1000);

  let result = [
    "UNIX timestamp: " + unixTimestamp,
    "",
    "Local.........: " + date.toString(),
    "UTC...........: " + date.toUTCString(),
  ].join("\n");

  return result;
})();

To use, simply select your Unix timestamp, and invoking the macro. It'll copy the selected timestamp into the pasteboard, convert it to human readable timestamps in both the local time-zone and in UTC, and show it in a dialog.

And that's pretty much it. Obviously not complicated, yet I've been finding myself using it quite a lot recently. Hope you find it just as useful as I have.

Last updated