`

Inside the AS3 Date class: Timezones and Daylight Saving Time

    博客分类:
  • AS3
 
阅读更多

from: http://www.computus.org/journal/?p=44

Inside the AS3 Date class: Timezones and Daylight Saving Time

 

Local time
The same moment in time has a unique local interpretation depending upon the time of year and your position on Earth. The operating system provides the Flash Player with two local temporal modifiers: One for Time zone designation (TZD) and one for Daylight saving time (DST). Local time is derived by applying these modifiers to the value of UTC.

Local time = UTC + TZD + DST

 


swf see the attachment. timezone.swf

Timezones: from ‘Keeping Track of Time with Flash MX’‘, New Riders 2002

Time zone (TZD)
I
f you ask two people at different longitudes “what time is it?” you will get two different answers. For example, when it is 11 am in New York, it is 4 pm in London and 1 am the following day in Tokyo. This is because the Earth is divided longitudinally (pole to pole) into 24 time zones spaced 15° apart. The areas within each time zone observe a local or ‘civil time’ one hour earlier than the zone immediately to the east.

Gotcha: Territories on a zone boundary decide which side of the zone they wish to be on. Consequently very few of the lines dividing the time zones are actually straight.

Daylight Saving Time (DST)
Thanks mainly to the efforts of a London builder named William Willett we have the controversial notion of daylight saving time (DST). This practice means that in some locations, all clocks are put one hour ahead of local (TZD) time during the summer months.

Gotcha: The Flash 5 Player incorrectly applies the DST rule for the US Pacific territory to all locations.

Gotcha: Although it’s easy to determine whether DST is in effect at the end user’s location, it’s a much bigger problem to determine it for any other location. The rules for DST are a muddy political affair that vary greatly from location to location, and year to year.

Determining the values of TZD and DST
It is often useful to know the difference between the current local time and the current UTC time. The following property returns the difference, measured in minutes.

 var tzo:Number = d.timezoneOffset

Gotcha: The term ‘timezoneOffset’ is a bit of a red herring as this value contains the combined offset for timezone and Daylight Saving Time.

The following code can be used to determine the individual values of TZD and DST. Both functions return their offsets in milliseconds.

public static function getTimezone():Number
{
  // Create two dates: one summer and one winter
  var d1:Date = new Date( 0, 0, 1 )
  var d2:Date = new Date( 0, 6, 1 )
 
  // largest value has no DST modifier
  var tzd:Number = Math.max( d1.timezoneOffset, d2.timezoneOffset )
 
  // convert to milliseconds
  return tzd * 60000
}
 
public static function getDST( d:Date ):Number
{
  var tzd:Number = getTimezone()
  var dst:Number = (d.timezoneOffset * 60000) - tzd
  return dst
}
  • 大小: 163.1 KB
分享到:
评论

相关推荐

    时区( timezones)

    时区(timezones)是地球表面上各个地理位置相对于世界协调时间(UTC)的偏移,用于统一全球的时间记录。Android系统,作为全球广泛使用的移动操作系统,需要能够准确处理不同地区用户的时间需求,这就涉及到MTK...

    timezones.json

    timezones.json

    Restore All Windows 7 Default Time Zones

    if your system lose some Time Zones, you can use this reg file to recover them.

    解决win7中时间和时区无法修改Time-Zones

    3. **系统文件损坏**:系统关键文件如`timezones.dll`或`tzutil.exe`损坏,也可能导致时区设置失效。使用系统文件检查工具(SFC /scannow)可以检查并修复这些文件。 4. **驱动程序冲突**:某些硬件驱动程序,尤其...

    Python库 | timezones-1.4.tar.gz

    3. **时区转换**:`timezones`库可以帮助我们轻松地将时间从一个时区转换到另一个时区。例如,将UTC时间转换为北京时区: ```python utc_time = datetime.datetime.now(tz.tzutc()) beijing_time = utc_time.as...

    jdk1.8_win64.rar

    The new API is easier to use, more accurate, and provides better support for time zones and daylight saving time. 5. **Nashorn JavaScript Engine**: JDK 1.8 includes the Nashorn JavaScript engine, ...

    countries-and-timezones:简约的图书馆,可处理国家和时区数据

    npm install --save countries-and-timezones 浏览器 将以下脚本添加到您的项目中(仅〜9kb): <!-- Latest version --> < script src =" ...

    timezones-list:时区列表

    时区列表 该软件包包含基于常规选项的一系列时区。 它不遵循任何完整的数据集,但几乎包含所有基本时区。...import timezones from 'timezones-list' ; // or var timezones = require ( 'timezones-list' ) ;

    timezones-json:时区列表

    1. **夏令时(Daylight Saving Time, DST)**:某些国家和地区会在夏季调整时间以充分利用日照,这需要额外的逻辑来处理。 2. **地理位置和政治变化**:随着时间的推移,某些地区的时区可能会因政治或地理因素发生变化...

    Laravel开发-timezones

    `timezones`这个话题在Laravel开发中至关重要,因为它涉及到如何正确地显示、存储和转换用户的时间数据。Laravel提供了一套强大的时间处理机制,使得开发者可以轻松地在全球范围内进行时区管理。 首先,Laravel使用...

    Laravel开发-laravel-gmt-timezones

    `laravel-gmt-timezones` 是一个专门为Laravel设计的扩展包,它帮助开发者更方便地管理和显示基于GMT(格林尼治标准时间)的时区,而不是常用的UTC(协调世界时)。这个扩展包是从`camroncade/timezone`进一步发展而...

    TimeZones.jl:对Julia编程语言的IANA时区数据库访问

    标题"TimeZones.jl:对Julia编程语言的IANA时区数据库访问"指的是一个名为`TimeZones.jl`的Julia语言库,该库专门用于处理和操作与时间区域相关的数据。IANA(互联网 Assigned Numbers Authority)是维护全球时区...

    Laravel开发-laravel-timezones

    `laravel-timezones`这个包是专门为Laravel设计的,用于更方便地管理和显示不同用户时区的时间。让我们深入了解一下这个包以及Laravel中与时间相关的知识点。 **1. Laravel的日期和时间类** Laravel使用Carbon库来...

    timezones:一个简单的时区数据集,其中包含国家_地区,国家_地区代码,UTCOffset和时区

    timeZones: [ "Asia/Kabul" ], UTCOffset: [ "UTC +04:30" ] } timeZones和UTCOffset数组与时区及其对应的UTCOffset匹配。 尽管有些国家/地区像这样一个时区: { countryCode: "CL", countryName: ...

Global site tag (gtag.js) - Google Analytics