英文:
Python convert string (from int64) to datetime
问题
You can convert the lastLogon
value from LDAP computer logon timestamp to datetime in Python using the following code:
import datetime
ldap_timestamp = 133322323232233542
# Convert LDAP timestamp to datetime
timestamp_datetime = datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=ldap_timestamp / 10)
print(timestamp_datetime)
这是将LDAP计算机登录时间戳转换为Python中的日期时间的代码。
英文:
Got this value from LDAP computer logon timestamp:
lastLogon: 133322323232233542
How to convert it to datetime in python ? (it looks like it's string for int64 representation ?)
Thanks,
答案1
得分: 1
以下是翻译好的代码部分:
似乎是字符串格式的Unix时间戳。为了在Python中将其转换为`datetime`对象,您可以使用`datetime`模块。
import datetime
timestamp = int("133322323232233542")
datetime_obj = datetime.datetime.fromtimestamp(timestamp / 10000000 - 11644473600)
print(datetime_obj)
英文:
It appears to be a Unix timestamp in a string format. In order to convert it to a datetime
object in Python, you can use the datetime
module.
import datetime
timestamp = int("133322323232233542")
datetime_obj = datetime.datetime.fromtimestamp(timestamp / 10000000
- 11644473600)
print(datetime_obj)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论