Link to home
Start Free TrialLog in
Avatar of Marco Gasi
Marco GasiFlag for Spain

asked on

How to manage requests from different time-zones in PHP

Hi everybody.
I'm working on the back-end of an Android native mobile app. This app will be used to create items, send and accept requests from other user and so on.
I'm wondering how to manage the time zones with these requests. If a Japanese user sends a request to a Spanish user, both users will have to see in their app the correct date and time for their timezones and the date and time will be different...
How can I manage this issue in the back-end?
I guess I should save date and time with the server time-zone (just adding a column timestamp with default value set to NOW); then when data are requested, get the time-zone the request comes from, take the timestamp from the db and convert it to the target time zone.
But I'm not sure if this is the better way to solve the problem and how to do it.

Any help will be appreciated )
SOLUTION
Avatar of Noah
Noah
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marco Gasi

ASKER

Hi guys.
Thank you for your answers. It looks that the Julian's thought about users moving between timezones is right.
So, Julian, if I correctly understand, I can just use in the DB a column of type TIMESTAMP and set its default to NOW; then ask the app developers to convert the timestamp returned in local datetime using Java functions (I have no control on the frontend code and they are not using javascript, just Java).
I'll check this with them and I'll come back here.
I'll leave the question open for the moment, just in case they have some objection.
Thank you again.
Java is server side - the nice thing with JavaScript is that you can tap into the User's locale settings so you will get the time they are expecting to see. If they move and they change their locale settings - the time will be automatically set to the new timezone.

If you don't have client access then not sure how you are going to get their timezone information short of doing an IP lookup. Under some pressure right now so there may be a solution here that I am not seeing but as far as I know this information is not available server side unless you put some script on the client to tell it.
Julian, Java is the language to develop Android applications, besides the rest. Here I'm talking about an Android applications developed within AndroidStudio, which uses Java: no Javascript, no Ajax. But the app runs locally, in the phone: it is the client and it can access to phone data like system date and time.
They already said they think it will be easy and I'm just waiting for a confirmation to award the points.
Thank you again :)
Sorry Marco, not taking the time to read properly - sounds like you are on top of it though.
Thank you guys. Julian solutions is the best to solve my issue. Thank yo again.
You are welcome Marco,