Sunday, August 05, 2007

Flex's DateTimeAxis renders in GMT by default!

I have to admit to that fact that getting used to Flash's Date class has been a struggle, especially in its new localized form. If you instantiate a Date with a single parameter, it assumes the parameter you supply is the number of milliseconds since UNIX was cool, and it also assumes you're specifying the time in GMT. All is fine. If, however, you instantiate a Date with several parameters, (specifying the day, month and tear etc... separately) it assumes that you're specifying the date in "clock-on-the-wall" time. Once you've created the Date object, its toString() method renders the time in "clock-on -the-wall" time.

The fun really starts when you render a collection of Date objects using Flex Charting. Despite the fact that the Date class's toString() method renders UTC times in "clock-on-the-wall" format by default, the mx.charts.DateTimeAxis class renders Date objects in a line series in UTC by default.
Thankfully the DateTimeAxis class has a property called displayLocalTime that you can set to "true" to get the Date objects rendered in "clock-on-the-wall" format but it's not the default.


Anonymous said...

Thanks a lot. I had just faced the problem ("axis value and chart values do not match" case) and by the help of this topic in your blog, I solved it.

kayrules said...

Many Thanks to you for the great tips

gorman said...

This is very helpful. I am struggling with working with UTC and the DateField. Your comments about instantiating dates are helpful. If you have any other pointers to flex date relater resources, please let us know.

Many thanks!