Created
May 14, 2014 03:15
-
-
Save Wind4/34242b9308efb43f5bc1 to your computer and use it in GitHub Desktop.
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> | |
/// DateTime转Unix时间戳 | |
/// </summary> | |
/// <param name="time"></param> | |
/// <returns></returns> | |
public static long ToTimestamp(this DateTime time) | |
{ | |
return (time.ToUniversalTime().Ticks - 621355968000000000) / 10000000; | |
} | |
/// <summary> | |
/// Unix时间戳转DateTime | |
/// </summary> | |
/// <param name="timestamp"></param> | |
/// <returns></returns> | |
public static DateTime FromTimestamp(this long timestamp) | |
{ | |
return new DateTime((timestamp * 10000000) + 621355968000000000, DateTimeKind.Utc).ToLocalTime(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment