In general when your game stops it should save the time to a file. When it starts up again it loads the stop time from the file and compares it to an online time server. You can make an http request to retrieve the user's time from a time server such as http://worldtimeapi.org. You need to know the user's time zone. E.g. https://worldtimeapi.org/api/timezone/America/New_York
Here is an example
var current_datetime
var previous_stop_time
func _ready():
# Load the last stop time from permanent storage
# previous_stop_time = ....
# Create an HTTP request node and connect its completion signal.
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.connect("request_completed", self, "_http_request_completed")
# Perform a GET request. The URL below returns JSON
var error = http_request.request("https://worldtimeapi.org/api/timezone/America/New_York")
if error != OK:
push_error("An error occurred in the HTTP request.")
pass
# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
var response = parse_json(body.get_string_from_utf8())
current_datetime=response["datetime"]
#
# Compare previous_stop_time with current_time
#
pass