Last active
February 13, 2017 18:24
-
-
Save JeffJacobson/9219744 to your computer and use it in GitHub Desktop.
Convert a JavaScript date expressed in milliseconds into a .NET DateTimeOffset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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