android - php mysql and mobile clients, displaying dates from UTC to different timezones -


i have restful php backend mysql, serves android , ios clients, have users different timezones, dates in database in utc.

in order show these dates in users current timezone, have spent days researching, , talking mobile developers, came proposal:

1) when android or ios device starts, sends current device time server, upon server calculates offset between 2 times , returns client, example -03:30

2) client stores response (-03:30), , sends in header field each request performing backend.

3) when php wants select date, gets request header value, validates , uses value following

"select convert_tz(field,'+00:00','-03:30')" 

is gist of has done? missing better solution?

i know opinion in above 3 steps, specially first step, since on first place thought mobile developers can perform calculation based on server timestamp, refused.

thanks help!

store dates in utc(gmt+0) in database, , retrieve them such database client (phone device).

then have each device apply offset upon receiving timestamp. potential example:

timezone tz = timezone.getdefault(); date databaseutctime = getfromdb(); int offsetfromutc = tz.getoffset(databaseutctime.gettime()) / 1000; 

if want share user's time including timezone, perhaps store timestamp not utc , converting without offset?

$t = date('d-m-y h:i:s', $raw_stored_time); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -