Skip to content Skip to sidebar Skip to footer

How To Convert A Really Long Timestamp Into Datetime (19 Digits) (9876432101234567890)

I am trying to manage some mods for a game, and to do that I'm trying to decode the metadata file that comes with every mod, called meta.cpp https://community.bistudio.com/wiki/Arm

Solution 1:

This weird timestamp is double value of unix timestamp read as int. You can use next functions for convertion:

from struct import pack, unpack
from datetime import datetime, timezone

def sick_timestamp_to_datetime(ts):
    double_value, = unpack("d", ts.to_bytes((ts.bit_length() + 7) // 8, "big"))
    return datetime.fromtimestamp(double_value * 1000000, timezone.utc)

def datetime_to_sick_timestamp(dt):
    double_value = dt.timestamp() / 1000000
    return int.from_bytes(pack("d", double_value), "big")

Post a Comment for "How To Convert A Really Long Timestamp Into Datetime (19 Digits) (9876432101234567890)"