Skip to content

Instantly share code, notes, and snippets.

@phx
Created September 8, 2013 08:14
Show Gist options
  • Save phx/6482865 to your computer and use it in GitHub Desktop.
Save phx/6482865 to your computer and use it in GitHub Desktop.
Get Apple Epoch Time from Unix Epoch Time
#/bin/bash
# 1) create function to get current Unix Epoch Time
EPOCHTIME () { date -u +%s; }
# $ EPOCHTIME
# 1378623423
# $ EPOCHTIME
# 1378623429
# 2) get Unix Epoch Time at 12am on January 1, 2001, as STATIC variable
APPLETIME="$(date -d 20010101 -u +%s)"
# $ echo $APPLETIME
# 978307200
# 3) create the function to obtain current Apple Epoch Time
APPLEPOCH () { echo "$(($(EPOCHTIME)-$(APPLETIME)))"; }
# $ APPLEPOCH
# 400349476
# $ APPLEPOCH
# 400349478
# now Apple Epoch Time can be referenced by a DYNAMIC variable like this:
# $ echo $(APPLEPOCH)
# 400349922
# $ echo $(APPLEPOCH)
# 400349926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment