wabbajack/Wabbajack.Common/TimeExtensions.cs

19 lines
518 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Common;
public static class TimeExtensions
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public static DateTime AsUnixTime(this long timestamp)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(timestamp);
return dtDateTime;
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public static ulong AsUnixTime(this DateTime timestamp)
{
var diff = timestamp - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return (ulong) diff.TotalSeconds;
2021-09-27 12:42:46 +00:00
}
}