private static readonly long UnixEpochTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;
public static long? ToJsonTicks(this DateTime? value)
return value == null ? (long?)null : (value.Value.ToUniversalTime().Ticks - UnixEpochTicks) / 10000;
public static long ToJsonTicks(this DateTime value)
return (value.ToUniversalTime().Ticks - UnixEpochTicks) / 10000;
Feel free to use this method in your applications. I offer no warranties or guarantees with the code above.