Skip to content

Instantly share code, notes, and snippets.

@hardboil
Created November 1, 2021 07:24
Show Gist options
  • Save hardboil/dc0d4b9853eb0083d2cf0081de0bc63c to your computer and use it in GitHub Desktop.
Save hardboil/dc0d4b9853eb0083d2cf0081de0bc63c to your computer and use it in GitHub Desktop.
convert mongoDB ObjectId to timestamp
# -*- coding: utf-8 -*-
from bson.objectid import ObjectId
from pytz import timezone, utc
# utc 값 반환
_insert_datetime = ObjectId("617f910d329d5f3a2aa22857").generation_time
print(_insert_datetime)
# 로컬 시간대로 변경
_insert_datetime_localtime = _insert_datetime.astimezone(timezone("Asia/Seoul"))
print(_insert_datetime_localtime)
# 포멧팅
print(_insert_datetime_localtime.strftime("%Y-%m-%d %H:%M:%S"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment