comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:961030992bd2
1 using System;
2
3 namespace IBBoard
4 {
5 /// <summary>
6 /// Summary description for UnixTimestamp.
7 /// </summary>
8 public class UnixTimestamp
9 {
10 private long stamp;
11 private static DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime();
12
13 public UnixTimestamp(DateTime date)
14 {
15 stamp = GetTimestamp(date);
16 }
17
18 public UnixTimestamp(long timestamp)
19 {
20 stamp = timestamp;
21 }
22
23 public DateTime GetDate()
24 {
25 return unixEpoch.AddSeconds(stamp);
26 }
27
28 public DateTime GetDate(int timestamp)
29 {
30 return unixEpoch.AddSeconds(timestamp);
31 }
32
33 public long GetTimestamp()
34 {
35 return stamp;
36 }
37
38 public static long GetTimestamp(DateTime date)
39 {
40 TimeSpan span = date.ToUniversalTime() - unixEpoch;
41 return (long)span.TotalSeconds;
42 }
43 }
44 }