I have an Azure Function App that runs every five minutes. The document has a Timestamp field using
DateTime.Now
I live in the UK which is currently british summer time 26-09-18 which is 1 hour ahead of GMT. My Azure data centre is UK South. The timestamp is one hour wrong. E.G. 20:01 is stored in the documnt as 19:01. How can I correct this?
Azure Functions by default are UTC.
For Windows TimeZone values check here
For Linux TimeZone values check here
You can handle this in code, for the UK, you can use the following which should auto adjust for daylight savings.
TimeZoneInfo ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
DateTime utcDate = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime ukTime = TimeZoneInfo.ConvertTimeFromUtc(utcDate, ukTimeZone);
Console.WriteLine(utcDate == ukTime);
On the 1st of January, the value of ukTime should be equal to UTC, as the time zone used in the UK at that time of year is the GMT time zone which is equal to UTC.

On the 1st of June, the time in the UK should be an hour ahead of UTC, as the UK will have switched over the the BST time zone during that time of year.
utcDate = new DateTime(2019, 6, 1, 0, 0, 0, DateTimeKind.Utc);
ukTime = TimeZoneInfo.ConvertTimeFromUtc(utcDate, ukTimeZone);
Console.WriteLine(utcDate == ukTime.AddHours(-1));

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With