Wednesday, January 13, 2016

DateTime.UtcNow vs DateTime.ToUniversalTime

Problem

I was updating an algorithm on a logging solution.  The time stamps were off due to the server sitting in Arizona and the process being started in Europe.  The issue was how to get the time displayed as true UTC time.

Solution

Initially I was playing with UtcNow in the namespace.  However, this will give you the local time of the server in UTC.  That is not what we were looking for!  We needed to use ToUniversalTime which gives the true time in UTC (Zulu). 

Source

  1. https://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx
  2. http://stackoverflow.com/questions/10884549/datetime-conversion-to-filetimeutc

No comments:

Post a Comment