Close

Convert local time to UTC

Sometimes you find yourself struggling with a datetime issue. This time I simply used DateTime.ToUniversalTime() at first, but that didn’t work for me. So, I decided to specifically include the time zone. I am in Amsterdam, so I tried to use the official Central European Summer Time (CEST) zone. Bad luck again. In C# you will have to use Central Europe Standard Time. It looks like like this timezone works both in summer and winter time. It works in summer time anyway. Here’s my tiny snippet of code:

string ceZoneId = “Central Europe Standard Time”;
TimeZoneInfo ceZone = TimeZoneInfo.FindSystemTimeZoneById(ceZoneId);
DateTime adjContactTijdstip = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(contactDateTime), ceZone);

* contactDateTime = “2018-07-04 14:33:00” (string value -> needs to be parsed)

Leave a Reply

Your email address will not be published. Required fields are marked *