0
votes

I have an UTC timestamp and I would like to display the corresponding date and hour in a specific timezone (e.g. France local time) which is not the local timezone of the computer which might be in US. It seems complicated to take into account Daylight saving time.

On Flash/as3 documentation, I only found the Date class which have no function to specify the timezone (only use local time or UTC).

2

2 Answers

2
votes

If I understand your problem, flash.globalization.DateTimeFormatter is your solution.

The DateTimeFormatter class provides locale-sensitive formatting for Date objects and access to localized date field names. The methods of this class use functions and settings provided by the operating system.

0
votes

Here's a function i found somewhere, probably right on stack oveflow to check if daylight savings is in effect.

public static function isObservingDTS(): Boolean {
  var winter: Date = new Date(2011, 01, 01); // after daylight savings time ends
  var summer: Date = new Date(2011, 07, 01); // during daylight savings time
  var now: Date = new Date();

  var winterOffset: Number = winter.getTimezoneOffset();
  var summerOffset: Number = summer.getTimezoneOffset();
  var nowOffset: Number = now.getTimezoneOffset();

  if ((nowOffset == summerOffset) && (nowOffset != winterOffset)) {
    return true;
  } else {
    return false;
  }
}

flex will keep a date in UTC and a timezone offset. any displaying of the date will show the timezone corrected form of the date, unless you calculate the new time and spit the date out as a string. something like this

private function convertToTimezone(dtDate: Date, timezoneOffset: Number = 0): String {
  //timezoneOffset in minutes
  dtDate.setTime(dtDate.getTime() + (timezoneOffset * 60000) + (isObservingDTS() ? (60 * 60 * 1000) : 0));

  return dtDate.toUTCString();
}

not very elegant, but it should get you there.