Created
May 4, 2022 09:01
-
-
Save onepointconsulting/a50adcde8286b9054d5d660b98239578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################################### | |
### Converts MongoDB timestamps to human readable dates | |
####################################################### | |
import sys | |
from datetime import datetime | |
args = sys.argv[1:] | |
if len(args) < 1: | |
print("Please enter the MongoDB ids you want to convert to timestamp") | |
sys.exit() | |
def dateFromObjectId(objectId): | |
seconds = int(objectId[:8], base=16) | |
return datetime.fromtimestamp(seconds).strftime('%Y-%m-%d %H:%M:%S') | |
for arg in args: | |
print(arg, dateFromObjectId(arg)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment