diff UnixTimestamp.cs @ 0:961030992bd2

Initial commit of IBBoard libraries
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 11:13:48 +0000
parents
children 0352fa33ee8f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnixTimestamp.cs	Fri Dec 19 11:13:48 2008 +0000
@@ -0,0 +1,44 @@
+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;
+		}
+	}
+}