-2

I use chrome timestamp and convert it do readable date but time isn't right

timestamp_formated = str(datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=last_visit_time))

Seems to be timezone need to be added

example for last_visit_time : 13292010189305268

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
None
  • 41
  • 7

2 Answers2

1

Assuming that Chrome timestamps denote microseconds since 1601 UTC, you'll want to make your datetime aware:

from datetime import datetime, timezone, timedelta

epoch = datetime(1601, 1, 1, tzinfo=timezone.utc)
timestamp = epoch + timedelta(microseconds=last_visit_time)
print(timestamp)

If you want to format it for a non-UTC timezone, add a conversion step:

local_timestamp = timestamp.astimezone(the_timezone)
deceze
  • 510,633
  • 85
  • 743
  • 889
0

if you'd like to localize(use timezone specific dates and time) you can use pytz for that

t = datetime(
2013, 5, 11, hour=11, minute=0,
tzinfo=pytz.timezone('Europe/Warsaw')

)

Izuki13
  • 54
  • 6
  • that is ***not*** how you localize with `pytz` - see [Weird timezone issue with pytz](https://stackoverflow.com/q/11473721/10197418). – FObersteiner Mar 29 '22 at 22:27