Mercurial > repos > IBBoard
view UnixTimestamp.cs @ 15:043a1d8101f2
* Rename "Convert" method to "ToArray" now that the class is more generic
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Jan 2009 13:25:23 +0000 |
parents | 961030992bd2 |
children | 0352fa33ee8f |
line wrap: on
line source
using System; namespace IBBoard { /// <summary> /// Summary description for UnixTimestamp. /// </summary> public class UnixTimestamp { private long stamp; private static DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime(); public UnixTimestamp(DateTime date) { stamp = GetTimestamp(date); } public UnixTimestamp(long timestamp) { stamp = timestamp; } public DateTime GetDate() { return unixEpoch.AddSeconds(stamp); } public DateTime GetDate(int timestamp) { return unixEpoch.AddSeconds(timestamp); } public long GetTimestamp() { return stamp; } public static long GetTimestamp(DateTime date) { TimeSpan span = date.ToUniversalTime() - unixEpoch; return (long)span.TotalSeconds; } } }