Debugger Trick when Working with UTC DateTimes

A couple days ago, this idea popped into my head when I was listening to a presentation at Austin Code Camp. I finally got around to giving it a try and it works like I hoped!

If I have a DateTime property that is set to UTC, I’m not great at doing the calculation in my head as quickly as I’d like. I was hoping I could leverage the DebuggerDisplayAttribute to show me both the Local time and the Universal time. It was actually really easy to hook up.

public class Issue
    public Issue()
        Created = DateTime.UtcNow;

    [DebuggerDisplay("Local = {Created.ToLocalTime()}, UTC = {Created}")]
    public DateTime Created { get; private set; }

Oh how I enjoy how helpful System.Diagnostics can be.

About Chris Missal

Oh hey, I'm a Senior Consultant for Headspring in Austin, TX. I've been working in software professionally since 2006 and I really, really love it. I'm mostly in the Microsoft world, but enjoy building computer things of all sorts (to be vague). When I'm not slinging code, I'm probably out and about slinging discs, bowling balls, or good beer with great friends.
This entry was posted in .NET, C# and tagged , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Justin

    I love it! Something so simple, too :) Suddenly, all my DateTime’s are about to mean something waaay more awesome for me :) Thanks heaps Chris … love the Debugger trick :) (especially as i always work with UTC DateTimes).

    • Hey no problem! Always good to know I have helped somebody out.