How can I make in-game time sync with a real timezone?

What are you attempting to achieve?
I want to have in-game time synced with real life in real-time. For example, if it was 10 AM GST (Gulf Standard Time), the TimeOfDay in Lighting would be 10 and it would change every second and every minute and every hour like real-life, so 10 hours later, it would be 8 PM as would the in-game TimeOfDay be 8 as well.

What is the issue?
I’m not an advanced scripter (but I do have one on my team since I work on a game with a group of developers using TeamCreate and Discord) and I’m also unsure if this would affect good performance.

What solutions have you tried so far?
None, although I know it’s possible because I’ve seen games with this feature before and it’s amazing.

Notes:
I would also add an override in my game to allow players to either chose their timezone (I’d probably go with common zones such as Eastern, Central, Pacific, and maybe some European ones) but the default would be on EST since it would appear my playerbase is from East US.
EDIT: This would actually mess up the time-based events in the game, so the override will not happen.

3 Likes

Using what Tiffblocks has explained brilliantly here, you can use the returned value from os.date("!*t",os.time()) to get the time in UTC, you can add a certain time to the os.time() value to get the date and time of different timezones.

1 Like

Thanks, but it appears the advanced scripter on my team found a way.

not really the best way to do it, but I have used a public time API and just fetched the current time using HttpService in the past.

I think this was the one I used:
http://worldclockapi.com/api/json/utc/now

3 Likes

oh, and just to add, @Crazyman32 created a ModuleScript for this purpose: https://www.roblox.com/library/182602810/GetDate

4 Likes