Search code examples
c#.netdatetimeutc

DateTime.UtcNow gives different value in different server


I have a dll that logs datetime in UTC using this code i.e. `DateTime.UtcNow() I am running a console application which uses this dll in two different servers. One server is in 'Easter Timezone' and the other is in 'Pacific Timezone'. Now when i launch the console application, i keep getting two different times.

e.g. In Easter Timezone: 11/18/2014 10:14:40 PM In Pacific Timezone: 11/18/2014 10:13:26 PM
Difference: 1:14

I launched the console application in the server that was running in EST first. And the time difference between launching two console applications in two servers was just couple seconds. Does anyone know why there is so much difference in timezone (UTC) while running the same code in two different servers?

Thanks. Sanjeev


Solution

  • The system clock on both servers could be slightly different.

    From the spec (emphasis added):

    Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

    http://msdn.microsoft.com/en-us/library/system.datetime.utcnow(v=vs.110).aspx