Created
March 16, 2010 12:15
-
-
Save karno/333902 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
namespace K.Particles | |
{ | |
static public class UnixEpoch | |
{ | |
const long EPOCH = 621355968000000000; | |
/// <summary> | |
/// Get Unix epoch from DateTime | |
/// </summary> | |
/// <param name="dt">DateTime</param> | |
/// <returns>Unix epoch</returns> | |
public static int GetUnixEpochByDateTime(DateTime dt) | |
{ | |
return (int)((dt.ToUniversalTime().Ticks - EPOCH) / 10000000); | |
} | |
/// <summary> | |
/// Get DateTime from Unix epoch | |
/// </summary> | |
/// <param name="epoch">Unix epoch</param> | |
/// <returns>DateTime</returns> | |
public static DateTime GetDateTimeByUnixEpoch(long epoch) | |
{ | |
DateTime unix = new DateTime(1970, 1, 1); | |
unix = unix.AddSeconds(epoch); | |
return unix.ToLocalTime(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment