2

What is the difference between DateTime.Now and DateTime.UtcNow.

Is there any performance difference?

Update : I read this article ( http://www.nayyeri.net/the-darkness-behind-datetime-now ) and I think we have a substantioal difference, don't you think ? I guess there should be something else.

Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100
  • 1
    Possible duplicate of [Optimizing alternatives to DateTime.Now](http://stackoverflow.com/questions/1561791/optimizing-alternatives-to-datetime-now), and related to [Computing Time in .NET](http://blogs.msdn.com/b/clrperfblog/archive/2009/09/08/computing-time-in-net.aspx) – Kobi May 25 '11 at 04:17

5 Answers5

4

DateTime.Now

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

DateTime.UtcNow

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

As for performance DateTime.Now is a little slower because of time zone adjustments.

You can find more details in THIS thread.

Community
  • 1
  • 1
Incognito
  • 16,567
  • 9
  • 52
  • 74
3
  • DateTime.Now - your OS system local time.
  • DateTime.UtcNow - UTC (GMT 0) time. What is UTC time.

Performance-wise - Now is slower than UtcNow, as Now actually calls UtcNow and does a few extra adjustments. However, the performance gain is minuscule and you can neglect it, unless you run this for enormous number of times repetitively.

Alex Aza
  • 76,499
  • 26
  • 155
  • 134
2

DateTime.UtcNow - Coordinated Universal Time (UTC).

DateTime.Now - local time

You should not be concerned about any performance difference. You use each where appropriate.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
1

Don't know if there is a measurable difference, but DateTime.UtcNow does less work. DateTime.Now starts with the value of DateTime.UtcNow, looks up your time zone offset in the current system settings and then adjusts the result. It also makes adjustments for daylight savings time.

Paul Alexander
  • 31,970
  • 14
  • 96
  • 151
0

DateTime.Now gives your PC date time as per your PC's Time zone

DateTime.UtcNow gives your date time as per GMT (Converts tour PC time to GMT and returns datetime)

Umesh CHILAKA
  • 1,466
  • 14
  • 25