When using a WCF or ASMX web service in ASP.NET, you might find the need to pass back a
DateTime object via JSON. However, what you might not realize is that by passing a .NET
DateTime object that resembles the following:
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;
Date() object and get the correct
DateTime value for my locale.
Feel free to use this method in your applications. I offer no warranties or guarantees with the code above.