Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Franz Wong
Franz Wong

Posted on

     

Time change in daylight saving

I live in a country not following daylight saving time. By writing this article, it helps me to understand what happens when daylight saving time starts and ends.

You can't stick with UTC all the time

Ideally, we should stick with UTC whenever possible. But most of us live with local time. For example, trading hour of New York stock exchange opens at 09:30 New York local time (or Eastern time). 09:30 ET is 13:30 UTC in summer or 14:30 UTC in winter. If you schedule a task with UTC time to do something when market opens, then you need to be aware of time change.

We will useEastern time as example in this article.

When daylight saving time starts

In March every year, we change from standard time to daylight saving time. We do a "clock forward", 1 hour is skipped in local time.

SOURCE_TIMEZONE=UTC&&TARGET_TIMEZONE=America/New_York# Change 2021-03-14 06:00 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-03-14 06:00"''# Sun Mar 14 01:00:00 EST 2021# Change 2021-03-14 06:59 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-03-14 06:59"''# Sun Mar 14 01:59:00 EST 2021# Change 2021-03-14 07:00 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-03-14 07:00"''# Sun Mar 14 03:00:00 EDT 2021
Enter fullscreen modeExit fullscreen mode

From the above, 02:00 is skipped.

After 01:59 (EST), it jumps ahead to 03:00 (EDT). The timezone changes fromEST (Eastern standard time) toEDT (Eastern daylight time).

So what if we try to format a time2021-03-14 02:00 ET toUTC?

SOURCE_TIMEZONE=America/New_York&&TARGET_TIMEZONE=UTC# Change 2021-03-14 02:00 ET to UTCTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-03-14 02:00"''# date: invalid date 'TZ="America/New_York" 2021-03-14 02:00'
Enter fullscreen modeExit fullscreen mode

We can't do that or the behaviour is unknown.

When daylight saving time ends

In November every year, we change from daylight saving time to standard time. We do a "clock backward", 1 hour is repeated in local time.

SOURCE_TIMEZONE=UTC&&TARGET_TIMEZONE=America/New_York# Change 2021-11-07 05:00 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-11-07 05:00"''# Sun Nov  7 01:00:00 EDT 2021# Change 2021-11-07 05:59 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-11-07 05:59"''# Sun Nov  7 01:59:00 EDT 2021# Change 2021-11-07 06:00 UTC to ETTZ=$TARGET_TIMEZONEdate--date='TZ="'"$SOURCE_TIMEZONE"'" '"2021-11-07 06:00"''# Sun Nov  7 01:00:00 EST 2021
Enter fullscreen modeExit fullscreen mode

From the above, 01:00 is repeated.

After 01:59 (EDT), it falls back to 01:00 (EST). The timezone changes fromEDT (Eastern daylight time) toEST (Eastern standard time).

Hope this help to maintain timezone sensitive application. I worked with a few data APIs (e.g. Reuters), some of their documentations contain mistakes with timezone.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Hong Kong
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp