Created
November 1, 2021 07:24
-
-
Save hardboil/dc0d4b9853eb0083d2cf0081de0bc63c to your computer and use it in GitHub Desktop.
convert mongoDB ObjectId to timestamp
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
| # -*- 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