I am working on Flex 3 application, and I would like to know how can I create Date object in actionscript3 that would represent particular timezone? My application is used internationally and I would like to create standard timezone for entire application, where as per research I found that I cannot create date object based on particular timezone. Any suggestions for this? and FYI all business logic resided on Java on server and for front end we are using flex.
UPDATE:
I am getting time from server to flex as "Fri Sep 28 05:16:37 EDT 2012" but when I instantiate in new Date(), its throwing me invalid date error. So I corrected it as "Fri Sep 28 05:16:37 GMT -0400 2012" and instantiated with new Date(), but results I get in IST, so timezone information lost. How can I preserve timezone in flex?
Assuming you want to store things as UTC....
In your server you can set the JVM parameter
-Duser.timezone=UTC
This will force the server to run as UTC regardless of the timezone of the computer.
Then as you are passing objects back from flex to java you will have to update the date object. Something like
var utcDate:Date = new Date(d.valueOf() - (d.timezoneOffset * MS_OF_ONE_MIN));
where d is your Date from flex and has the timezone of the PC Flex is running on.
If you are using something like BlazeDS then you can call a function to convert all your dates in the RemoteObject as that is your object that does the serialisation.
The big problem you have is that there is no setTimezone on a flex Date object which means you have to jump through all these hoops to get a UTC date.
Use UTC fields out of Date object to receive uniform time. Then, you can use getTimezoneOffset() to receive how far is current computer from UTC. Otherwise, please clarify your question, I can't decipher what do you actually need besides operating strictly in UTC data from local Date objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With