12345678910111213141516171819202122232425262728 |
- namespace System;
- public class CurrentTimeGetter
- {
- private static int lastTicks = -1;
- private static DateTime lastDateTime = DateTime.MinValue;
- /// <summary>
- /// Gets the current time in an optimized fashion.
- /// </summary>
- /// <value>Current time.</value>
- public static DateTime UtcNow
- {
- get
- {
- int tickCount = Environment.TickCount;
- if (tickCount == lastTicks)
- {
- return lastDateTime;
- }
- DateTime dt = DateTime.UtcNow;
- lastTicks = tickCount;
- lastDateTime = dt;
- return dt;
- }
- }
- }
|