wasSharp – Blame information for rev 18
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
18 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System; |
||
8 | |||
9 | namespace wasSharp.Timers.Utilities |
||
10 | { |
||
11 | public static class TimeExtensions |
||
12 | { |
||
13 | /// <summary> |
||
14 | /// Convert an Unix timestamp to a DateTime structure. |
||
15 | /// </summary> |
||
16 | /// <param name="unixTimestamp">the Unix timestamp to convert</param> |
||
17 | /// <returns>the DateTime structure</returns> |
||
18 | /// <remarks>the function assumes UTC time</remarks> |
||
19 | public static DateTime UnixTimestampToDateTime(this uint unixTimestamp) |
||
20 | { |
||
21 | return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTimestamp).ToUniversalTime(); |
||
22 | } |
||
23 | |||
24 | /// <summary> |
||
25 | /// Convert a DateTime structure to a Unix timestamp. |
||
26 | /// </summary> |
||
27 | /// <param name="dateTime">the DateTime structure to convert</param> |
||
28 | /// <returns>the Unix timestamp</returns> |
||
29 | /// <remarks>the function assumes UTC time</remarks> |
||
30 | public static uint DateTimeToUnixTimestamp(this DateTime dateTime) |
||
31 | { |
||
32 | return (uint) (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; |
||
33 | } |
||
34 | } |
||
35 | } |