• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1589
  • Last Modified:

Keep same timezone on all clients in different timezones

We work on a Flex application (sdk 3.4), we need to display dates stored in a mysql database with a Java application server by BlazeDS. But we must make treatments on the dates in flex application. All with the same timezone that can be stored in the database.

The best solution found so far is to manipulate the dates during the transfer BlazeDS: http://cookbooks.adobe.com/post_Date_time_transfer_in_BlazeDS-13114.html

This solution does not solve the problem of instantiating the date made flex side and treatment on those dates.

Do you have a more general solution? Knowing that the class date is final and that it is not possible to set timezone on flash player
0
KCTeam
Asked:
KCTeam
  • 2
1 Solution
 
wannabetechieCommented:
If you are not interested in showing the date with the timezone of the client then cant the date stored in your database be converted into a String while sending back the data to the Flex.
Probably can be done as part of your business logic which creates the Java objects that needs to be sent to the BlazeDS.
0
 
KCTeamAuthor Commented:
This solution may be  good for display but not for the instantiating and treatments made on flex application side.
0
 
petiexCommented:
What I do is to get the server GMT offset in minutes with this line of Java:
int minutesOff = TimeZone.getDefault().getOffset(new Date().getTime()) / 60000;

and, when the application loads, pass that value into it, and store that to a global variable, call it gOffset: int.

So, to generate a timestamp on the client using the server's offset, or whichever other offset you want, you can use the getCurrentServerTime() function below.
public var gOffset; //set from the server at some point before 
                    // calling getCurrentServerTime

/**
* Returns the current time adjusted to the server's timezone  
* (gOffset).
*/
public function getCurrentServerTime():Date{
        var now:Date = new Date();
        // date.getTimezoneOffset() returns
        // "The minutes you need to add to the computer's local 
        // time value to equal UTC."
        // so, for EST it gives you 300 instead of -300. 
       // Opposite of java.
        var clientOffset:Number = - now.getTimezoneOffset(); 
        var nowTime:Number = now.getTime();
        var adjustedOffset:Number = gOffset - offset,
        var milliOffset:Number = adjustedOffset * 60000;
        //convert client time to center time
        nowTime += (milliOffset);
        now = new Date(nowTime);
        return now;
}

Open in new window

0
 
KCTeamAuthor Commented:
The  solution is interesting , but we wanted a more general since the  application is already implemented so we wanted to have one solution  does not require changing all instantiating like to change the TimeZone  of flash player
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now