How to display the current time in British Summer Time using C#

Posted written by Paul Seal on March 28, 2022 .NET Framework

I was asked by someone to help them display the current date and time as it is in British Summer Time or Daylight Saving Time on their website using C# Here is the solution I gave them:

//get the current UTC time
DateTime localServerTime = DateTime.UtcNow;

//Find out if the GMT is in daylight saving time or not.
var info = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
var isDaylightSaving = info.IsDaylightSavingTime(localServerTime);

//set the time to be the local server time
var correctDateTime = localServerTime;

//if the zone is in daylight saving add an hour.
if (isDaylightSaving)
{
    correctDateTime = correctDateTime.AddHours(1);
}

//get the UK culture and return the correct date time in the correct format
var culture = new CultureInfo("en-GB");
Console.WriteLine(correctDateTime.ToString(culture));

I know it is specific to GMT and BST but you could take it and modify it to your needs.