How to create a date in actionscript with a specific time zone?

I am working on a Flex 3 application and I would like to know how can I create a Date object in actionscript3 that will represent a specific timezone? My application is used internationally, and I would like to create a standard time zone for the entire application, where, according to research, I found that I can not create a date object based on a specific time zone. Any suggestions for this? and FYI, all the business logic was in Java on the server, and for the front end we use flex.

UPDATE:

I get the time from server to flex as "Fri Sep 28 05:16:37 EDT 2012", but when I create an instance in the new Date (), it throws me an invalid date error. Therefore, I fixed it as "Fri Sep 28 05:16:37 GMT -0400 2012" and was created with a new Date (), but I get the results in IST, so the time zone information is lost. How to save time range in flex?

+4
source share
3 answers

Assuming you want to store things like UTC ....

On your server you can set the JVM parameter

-Duser.timezone=UTC 

This will make the server work as UTC regardless of the time zone of the computer.

Then, when you pass the objects back from flex to java, you will have to update the date object. Sort of

  var utcDate:Date = new Date(d.valueOf() - (d.timezoneOffset * MS_OF_ONE_MIN)); 

where d is your date from flex and has the time zone on the Flex computer.

If you use something like BlazeDS, you can call a function to convert all of your dates to RemoteObject , as this is your serialization object.

The big problem you are facing is that there is no setTimezone in the Flex Date object, which means you have to jump over all these hoops to get the UTC date.

+4
source

Use the UTC fields from the Date object to get uniform time. Then you can use getTimezoneOffset () to get how far the current computer is from UTC. Otherwise, please clarify your question, I can not decrypt what you really need, except for strictly working in UTC data from local Date objects.

+3
source

Ideally, nothing should take care of your server side timezone, including your server. Server location is unlikely to be of any use to businesses, and it can be very useful to be able to run servers wherever you want.

Instead, you need to figure out what your user interface is. Is this a local date and time that is actually a timezone neutral? Is it โ€œjust a dateโ€ that will again be neutral in the time zone? Is this a specific point in time (for example, when did a particular phone call occur, regardless of where it occurred)? (There are more options, but they are the most common.)

Once you have determined what your data really means, you can find the right way to pass this to the server (you did not tell us anything about it), and then how to present it to the server. Your server-side code will become much clearer if you use Joda Time instead of the built-in classes java.util.Date and java.util.Calendar ... you can imagine each of the above concepts with a suitable Joda time type.

As I said, the first thing to reset is the idea that you really have to work in the serverโ€™s time zone - or at least you have to justify this as an extremely unusual and potentially expensive solution.

+1
source

Source: https://habr.com/ru/post/1436747/


All Articles