Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Created February 7, 2014 01:03
Show Gist options
  • Save daryltucker/8855707 to your computer and use it in GitHub Desktop.
Save daryltucker/8855707 to your computer and use it in GitHub Desktop.
Convert ObjectId into Epoch
import datetime
import calendar
import time
def objectid_to_epoch(_id)
epoch = datetime.datetime.fromtimestamp(int(str(_id)[0:8], 16))
return calendar.timegm(datetime.datetime(epoch.year, epoch.month, epoch.day, epoch.hour, epoch.minute).utctimetuple())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment