Skip to content

Instantly share code, notes, and snippets.

@GrantBirki
Created March 1, 2022 07:49
Show Gist options
  • Save GrantBirki/708a4de18d734502b2bbf85721d740f4 to your computer and use it in GitHub Desktop.
Save GrantBirki/708a4de18d734502b2bbf85721d740f4 to your computer and use it in GitHub Desktop.
Tarkov Time in Python
from datetime import datetime
# 7 seconds for every one second in real time
TARKOV_RATIO = 7
def real_time_to_tarkov_time(time, left = True):
"""
Convert real time to Tarkov time
:param time: Current UTC epoch in milliseconds -> int(datetime.datetime.utcnow().timestamp()) * 1000
:param left: True if left side, False if right side (Think eft in-game clock)
:return: String of the time in the following format: %H:%M:%S
"""
# tarkov time moves at 7 seconds per second.
# surprisingly, 00:00:00 does not equal unix 0... but it equals unix 10,800,000.
# Which is 3 hours. What's also +3? Yep, Russia. UTC+3.
# therefore, to convert real time to tarkov time,
# tarkov time = (real time * 7 % 24 hr) + 3 hour
one_day = hrs_to_milliseconds(24)
russia = hrs_to_milliseconds(3)
if left:
offset = russia
else:
offset = russia + hrs_to_milliseconds(12)
tarkov_time = datetime.fromtimestamp((((offset + (time * TARKOV_RATIO)) % one_day) / 1000))
return tarkov_time.strftime("%H:%M:%S")
def hrs_to_milliseconds(num):
"""
Convert hours to milliseconds
:param num: number of hours
:return: milliseconds (Int)
"""
return 1000 * 60 * 60 * num
def utc_milli_timestamp():
"""
Get current UTC time in milliseconds
:return: UTC time in milliseconds (Int)
"""
return int(datetime.utcnow().timestamp()) * 1000
if __name__ == '__main__':
time = utc_milli_timestamp()
print(real_time_to_tarkov_time(time, left = True))
print(real_time_to_tarkov_time(time, left = False))
# Example output of this script
# Line 1: 09:40:47
# Line 2: 21:40:47
@GrantBirki
Copy link
Author

This script gets the current in-game time in Tarkov. This code was adapted from here which is originally written in JavaScript.

I needed the following code to work in Python so I adapted it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment