0

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,

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
user2913139
  • 557
  • 2
  • 5
  • 13

1 Answers1

1

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)
traizooo
  • 144
  • 14
  • 1
    You could add `tz=datetime.timezone.utc` keyword to `formtimestamp` to have the output in UTC. That avoids the "local time" trap Python offers. – FObersteiner Jun 26 '23 at 06:50