Thursday, October 27, 2016

How to Show the Local Build Time on .Net Web Pages

Grant Erickson has a great post on how to display the compile time in a razor page by editing the AssemblyInfo class.  This technique was first pioneered by
 Jeff Atwood here.
 This shows the GMT date which is true, but sometimes not as helpful when everyone has to translate that to their local time.

You can convert the time to local time, and display the local time zone on the layout page with this tiny bit of razor code:

[For Testing Only - Compile time: @(My.Namespace.WebUI.Properties.AssemblyInfo.Date.ToLocalTime().ToString("dddd MMMM d, hh:mm tt",CultureInfo.CreateSpecificCulture("en-US")))
            (@TimeZone.CurrentTimeZone.StandardName)  on @System.Environment.MachineName]

  Here's the resulting human readable time stamp:

[For Testing Only - Compile time: Thursday October 27, 03:20 PM (Central Standard Time) on US-ATX-Mordor022]

 This is helpful for QA personnel scattered over the world to know the build date of the system they are testing.

1 comment:

Dawid Yhisreal said...

Hey Mitch! just read this. So is this something we will see in the future or is this already implemented! If so we should add this to part of our team development tools!!