java - Get server date time with different timezone -


i want show server date time client side has same status of server datetime. date used achieve schedule-wise feature. following steps:

  • fetched initial date time server , calculated time date.gettime() difference.

  • add time diff client datetime

  • update client time using timer of gwt

it working fine when server timezone , client timezone both same. gives me wrong calculation different timezone.

just example: if client time indian timezone

((utc+05:30) chennai, kolkata, mumbai, new delhi)

and sever timezone

((utc-08:00) pacific time (us & canada))

so calculates wrong server date.

how can show current server time different timezone of server , client without making server request?

note: solution should universal timezone.

edit:

i used rpc mechanism , returning new date().gettime() server client. , in success method, client side code:

final string serverdate;             final datetimeformat fmt = datetimeformat.getformat(dateformat);             if(dateformat!=null){                 serverdate = fmt.format(result.getserverdate());             }else{                 serverdate = result.getserverdate().tostring();             }             setdatetime(serverdate,widget);             final long datediff = result.getserverdate().gettime()-new date().gettime();             timer timer = new timer() {                 @override                 public void run() {                     long currenrdate=new date().gettime()+datediff;                     date date=new date(currenrdate);                     string serverdate = fmt.format(date);                     setdatetime(serverdate,widget);                     workflowsessionfactory.putvalue(workflowsesisonkey.server_date_time,date);                    }             };             timer.schedulerepeating(10000); 

did try thing this?

    simpledateformat f = new simpledateformat("yyyy-mm-dd hh:mm:ss");     f.settimezone(timezone.gettimezone("utc"));     date date=new date();     system.out.println(f.format(date));   // current utc time      calendar cal = calendar.getinstance();     cal.settime(date);     cal.add(calendar.hour_of_day, 5);     cal.add(calendar.minute, 30);     system.out.println(f.format(cal.gettime()));// current client side time in utc      calendar cal2 = calendar.getinstance();     cal2.settime(date);     cal2.add(calendar.hour_of_day, -8);     cal2.add(calendar.minute, 00);     system.out.println(f.format(cal2.gettime()));// current server side time in utc 

Comments