Sign In Register

How can we help you today?

Start a new topic
Answered

Get time zone for player

I want to get the time zone for each player. Is there any suggested way to do this?


I want to have a time offset field for each player, so I can send global push notifications at appropriate times.


Best Answer
Hey Baris,

The server has no way to determine the time for the player itself, other than the geolocation (which is unfortunately not always accurate).
The conventional way of doing this is to submit the client's local-time to the server on authentication and calculate the time-difference (timeDelta) and store that on the player-doc.
If you then need to preform and time-based calculations or comparisons, you add/subtract the timeDelta for each player.

Does that make sense?
Sean

 


1 person has this question

Hi Baris,


If using Unity you could pass the timezone info in an event. The TimeZoneInfo class should be useful.

Thanks,


Oisin


Answer
Hey Baris,

The server has no way to determine the time for the player itself, other than the geolocation (which is unfortunately not always accurate).
The conventional way of doing this is to submit the client's local-time to the server on authentication and calculate the time-difference (timeDelta) and store that on the player-doc.
If you then need to preform and time-based calculations or comparisons, you add/subtract the timeDelta for each player.

Does that make sense?
Sean

 

Yes, this is a good idea, thanks. We'll use this in addition to TimeZoneInfo. 

For the previous users for whom we didn't have this info though, I intend to use a BulkJob to convert country data to time offsets. Do you have any suggestions for doing this?


( If anyone intends to use TimeZoneInfo for this, but for some users it can't find a TimeZoneInfo and causes an exception, so make sure to wrap it in a try-catch block. ) 

Hi Baris, currently looking into a solution for you.

Best Regards, Patrick. 

Login to post a comment