I'm designing a function that given a UTC timestamp will convert it to the local time.

The question I have, should the current times DST settings be applied to the conversion, or the timestamps DST settings?

If going with the former, current DST setting applied to timestamp - it would mean 4pm that was recorded with DST+1 would be 3pm with DST+0 and 4pm with DST+0, depending on the time of the year you checked the date at.

If going with the latter, the timestamps DST setting would be applied to it - so 4pm recorded with DST+1 will always say 4pm, no matter what time of the year you've checked it at.

Which is more preferrable in practice?

1 Answer 1


Use the DST settings applicable to the timestamp. This will apply the correct conversion rules. For example if I use the current DST status a local time in January would be incorrectly converted, as I am currently in DST and January uses ST here.

Most languages already have a function or method to do the conversion. Unless you have strong reasons to write your own, use it. This code should provide a way to determine if the the timestamp is DST or ST.

Many protocols use a format which includes the offset from UTC, as a suffix. For example:

Delivery-date: Sat, 14 Sep 2013 06:47:18 -0400

There are a lot of pitfalls in writing your own code:

  • Rules change from time to time.
  • Timezone change is often not done at midnight.
  • Rules can be different for different locations in the same timezone.
  • Leap seconds may or may not be included in the time stamps.

The Olson Time Zone Database contains an accurate rule set and is frequently updated.

  • So then-DST settings - thanks! I'm doing this for Lua, which doesn't quite have it, but has the capabilities to add it. Sep 15, 2013 at 4:32
  • @Vadi I see, Lua may not have the space for a full timezone rule set. You may want to look how the TZ variable is handled by the c library you are using. It may support applying the current timezone rules for the timezone if specifed in the variable. This leave you the task of setting it correctly.
    – BillThor
    Sep 15, 2013 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.