Jonathan Birkholz

London Time?

A friend ping’d me on gchat and asked if he had a DateTime object with our time in Texas, how could he get the time in London.

I quickly threw together this example on how I would do it.

1
2
3
4
5
6
7
8
9
10
11
12
DateTime time = DateTime.Now;
TimeZoneInfo londonTimeZone = TimeZoneInfo
.GetSystemTimeZones()
.FirstOrDefault(t => t.DisplayName.Contains("London"));
DateTime londonTime = TimeZoneInfo.ConvertTime(time, londonTimeZone);
Console.WriteLine("Its {0} here", time);
Console.WriteLine("But its {0} in London", londonTime);
Console.WriteLine("Blimey!");
Console.ReadLine();

C#