UTC to Central Time conversion - time

I have a dataset in which the time stamp is UTC. I want to convert it into Central Time (CDT/CST), including the daylight saving time switches(CDT= UTC-5, CST=UTC-6). I cannot use [DateTimetoLocal] function because our Alteryx server runs on GMT. If I use this function the the time stamp will get converted into GMT instead on CDT/CST.
How can I convert this time stamp in Central Time (CDT/CST), taking daylight savings into consideration?

Related

How to convert a UTC date time to Eastern Standard Time (GMT-5)

How can I convert a UTC date/time to Eastern Standard Time (GMT-5)? I'm mostly worried about Daylight Savings, so I can not simply do MyUTCDateTime - 5 hours (I think).

Sort local time by UTC time

Is there anything wrong with sorting local time by UTC timestamp?
I store time as Unix timestamps in UTC and output local time in a pretty complex format that is user friendly but would be a nightmare to sort. So I decided to sort it by UTC time.
Here is an exaggerated example:
<td data-utc-timestamp="1514372400">
<b>7:00<i>PM</i></b> December 27th,
beautiful Wednesday evening in Shanghai,
the year of the Rooster, 2017 :D
</td>
Seems perfectly fine to me to sort this by UTC timestamp, but I am not an expert in the field so I am having doubts.
Is there any scenario where an array of UTC times will have a different order than the same array of UTC times converted to local times?
UTC time is constant (i.e. there is no day light savings time or time changes ever). The only time that an issue is possible is when your local time observes DST. The sorting during the transition might mess you up. But as long as you handle that properly (i.e. your time codes are ordered correctly), UTC time and local time will mesh.
This answer has more details: Does UTC observe daylight saving time?

What happens to milliseconds since epoch when daylight savings time begins/ends?

Milliseconds since epoch represents the number of milliseconds that have elapsed since 1970. At the instant before daylight savings time ends, or when we set the clocks back to 1:00 from 2:00, do the milliseconds since epoch fall back as well, or do they continue?
Another question: If I live in California, US, which is on Pacific (Daylight/Standard) Time, is the milliseconds since epoch the same there as it is in, say, New York, on Eastern (Daylight/Standard) Time?
The milliseconds since epoch are not influenced by timezones and daylight saving time (daylight saving time just changed the timezone with -1 / +1).
The milliseconds/seconds since epoch are (always?) in UTC (or GMT + 0).
Milliseconds since the UNIX epoch (January 1, 1970 00:00:00 UTC) aren't affected by daylight savings and timezones as J. van Dijk mentioned.
To answer your 2nd question explicitly, which i think is important to understand UTC itself: if 2 people call System.currentTimeMillis() in Java or new Date().getTime() in Javascript at the same time, one of them being in California and one of them being in New York they should get the same number of milliseconds.

UTC time explanation

Can anybody explain me what it means when I have the following time:
2012-12-28T18:12:33+01:00
I'm new to the whole datetime stuff and I can't find a good explanation on the web.
Currently I'm in Holland. So does it mean:
2012-12-28T18:12:33+01:00 = 2012-12-28 19:12:33
or
2012-12-28T18:12:33+01:00 = 2012-12-28 17:12:33
or
2012-12-28T18:12:33+01:00 = 2012-12-28 18:12:33
The 2012-12-28T18:12:33+01:00 date string indicates that it is 2012-12-28 at 18:12 in the timezone that corresponds to +1 hour from UTC, which is CET timezone.
This appears to be the ISO 8601 format. The T indicates start of the time element.
Times are expressed in local time, together with a time zone offset in
hours and minutes. A time zone offset of "+hh:mm" indicates that the
date/time uses a local time zone which is "hh" hours and "mm" minutes
ahead of UTC. A time zone offset of "-hh:mm" indicates that the
date/time uses a local time zone which is "hh" hours and "mm" minutes
behind UTC.
The value you provided 2012-12-28T18:12:33+01:00 is an DateTime+Offset value in ISO8601 format, meaning "December 12th, 2013 at 18:12:33, one hour ahead of UTC".
The +01:00 portion represents an offset, not a time zone. See TimeZone != Offset.
The time zone for Holland is either Europe/Amsterdam in the IANA/Olson database, or the entry in the Windows database that has the Id of W. Europe Standard Time and the English display name of "(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna".
This zone is in the +01:00 offset during part of the year, and uses the +02:00 offset during European Summer Time.
Just because you have +01:00 in December, does not mean that is the correct offset to use year-round. It also does not tell you that the timestamp is in Holland. There are several other time zones that use the same offset, and not always at the same times of year.
To convert from one time zone to another, you need to first apply the offset you have. Use the inverse of the sign you have. Since you have +01:00, you would subtract an hour to get the UTC time of 17:12:33. Then you need to know what the correct offset is for the target time zone at that time of year. For that, you need a time zone database.
International Standard ISO 8601 specifies numeric representations of date and time.
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
where:
YYYY = four-digit year
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
s = one or more digits representing a decimal fraction of a second
TZD = time zone designator (Z or +hh:mm or -hh:mm)
Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z").
Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC. A time zone offset of "-hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes behind UTC.
In your case: 2012-12-28T18:12:33+01:00 = 2012-12-28 18:12:33 is true. Meaning the time in Holland is 18:12 and you are 1 hour ahead of UTC.

Subroutine to apply Daylight Bias to display time in local DST?

UK is currently 1 hour ahead of UTC due to Daylight Savings Time. When I check the Daylight Bias value from GetTimeZoneInformation it is currently -60. Does that mean that translating UTC to DST means DST = UTC + -1 * DaylightBias, ie negate and add?
I thought in this case for instance adding Daylight Bias to UTC is the correct operation, hence requiring DaylightBias to be 60 rather than -60.
It's
UTC = DST + DaylightBias [for your specific timezone]
so yes, you would subtract the Bias from UTC to get local time.
Here's a quote from the MS glossary:
time zone bias: The positive, zero, or
negative offset in minutes from
Coordinated Universal Time (UTC). For
example, Middle European Time (MET,
GMT+01:00) has a time zone bias of
"-60" because it is one hour ahead of
UTC. Pacific Standard Time (PST,
GMT-08:00) has a time zone bias of
"+480" because it is eight hours
behind UTC.

Resources