I am confused by "GMT Standard Time".
I have data which is stored as DATE only, but is actually 6PM BST.
I read it in and add 18 hours. I then try to convert to UTC. My initial understanding is that the conversion would NOT take into account Daylight time (as "GMT Standard Time" and UTC are both WITHOUT daylight time). I thought I would have to test for daylight time on the source and then make an adjustment.
However, ConvertTime appears to know about Daylight time in the source and makes the appropriate change.
That seems odd to me - is this the expected behaviour?
TimeZoneInfo gmtZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
TimeZoneInfo utcZone = TimeZoneInfo.FindSystemTimeZoneById("UTC");
public static CultureInfo ci = CultureInfo.InvariantCulture;
string SomeDT = "27/01/2000"; //First BST day
var sourceDT = DateTime.ParseExact(SomeDT, "dd/MM/yyyy", ci).AddHours(18);
var utcDT = TimeZoneInfo.ConvertTime(sourceDT, gmtZone, utcZone);
// At this point utcDT has already been changed so test below is redundant.
// That Suggest "GMT Standard Time" is actually "Daylight Time" i.e.BST
if (gmtZone.IsDaylightSavingTime(sourceDT))
{
utcDT = utcDT.AddHours(-1);
}
else
{
Console.WriteLine("Not BST");
}
The problem is that the time zone IDs in Windows are confusing. Even though the ID is "GMT Standard Time", the time zone referred to by that ID is really "UK time"... like "Europe/London" in IANA. So yes, it will observe DST.
If you want genuine UTC, just use TimeZoneInfo.Utc
.
(Alternatively, use Noda Time or something similar instead, and the more standard IANA time zones...)
See more on this question at Stackoverflow