16
|
1 // This file (UnitTimestamp.cs) is a part of the IBBoard library and is copyright 2009 IBBoard.
|
|
2 //
|
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
|
|
4
|
37
|
5 using System;
|
|
6
|
|
7 namespace IBBoard
|
|
8 {
|
|
9 /// <summary>
|
|
10 /// Summary description for UnixTimestamp.
|
|
11 /// </summary>
|
|
12 public class UnixTimestamp
|
|
13 {
|
|
14 private long stamp;
|
|
15 private static DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime();
|
|
16
|
|
17 public UnixTimestamp(DateTime date)
|
|
18 {
|
|
19 stamp = GetTimestamp(date);
|
|
20 }
|
|
21
|
|
22 public UnixTimestamp(long timestamp)
|
|
23 {
|
|
24 stamp = timestamp;
|
|
25 }
|
|
26
|
|
27 public DateTime GetDate()
|
|
28 {
|
|
29 return unixEpoch.AddSeconds(stamp);
|
|
30 }
|
|
31
|
|
32 public DateTime GetDate(int timestamp)
|
|
33 {
|
|
34 return unixEpoch.AddSeconds(timestamp);
|
|
35 }
|
|
36
|
|
37 public long GetTimestamp()
|
|
38 {
|
|
39 return stamp;
|
|
40 }
|
|
41
|
|
42 public static long GetTimestamp(DateTime date)
|
|
43 {
|
|
44 TimeSpan span = date.ToUniversalTime() - unixEpoch;
|
|
45 return (long)span.TotalSeconds;
|
|
46 }
|
|
47 }
|
|
48 }
|