C# Convert date from UTC to EST

Published on Jun 7, 2017 by Jamie Munro

Every now and then I need to convert a date from Coordinated Universal Time (UTC) to Eastern Standard Time (EST).  I always found myself trying to remember "Where did I use this last?".  To avoid asking myself, I have now immortalized it on my blog.

Here is the code that uses .NET's built-in functions to a from a UTC date to a specific timezone:

var timeUtc = DateTime.UtcNow;
var easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var today = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);

First thing we do is create a new date with UtcNow.  This of course could be any other UTC date you wish to convert.  Next we found the TimeZoneInfo object relating to my time zone "Eastern Standard Time".  And finally, I call the static ConvertTimeFromUtc function in the TimeZoneInfo class supplying my UTC date and TimeZoneInfo object.

If you need help finding your time zone, review Microsoft's Time Zone Index Values.

Tags: ASP.NET | c# | timezones

Related Posts

blog comments powered by Disqus