Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JeffJacobson/9219744 to your computer and use it in GitHub Desktop.
Save JeffJacobson/9219744 to your computer and use it in GitHub Desktop.
Convert a JavaScript date expressed in milliseconds into a .NET DateTimeOffset.
/// <summary>
/// Converts from a JavaScript Date value in milliseconds to a <see cref="DateTimeOffset"/>.
/// </summary>
/// <param name="milliseconds">Number of milliseconds since 1970-1-1T00:00:00</param>
/// <returns>Returns the <see cref="DateTimeOffset"/> equivalent of <paramref name="milliseconds"/>.</returns>
public static DateTimeOffset FromJSDateToDateTimeOffset(this double milliseconds)
{
return new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddMilliseconds(milliseconds * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment