feat: add methods for creating a DateTime from epoch seconds or millis

This commit is contained in:
Jeffery Thompson
2020-02-11 11:31:42 -05:00
parent 13d1072d10
commit 0b8eb82e3b

View File

@@ -1,4 +1,6 @@
namespace ICD.Common.Utils
using System;
namespace ICD.Common.Utils
{
public static class DateTimeUtils
{
@@ -11,5 +13,25 @@
{
return MathUtils.Modulus(hour + 11, 12) + 1;
}
/// <summary>
/// Creates a DateTime from the given number of milliseconds since the epoch (1970-01-01T00:00:00Z)
/// </summary>
/// <param name="milliseconds">milliseconds since the epoch</param>
/// <returns></returns>
public static DateTime FromEpochMilliseconds(long milliseconds)
{
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(milliseconds);
}
/// <summary>
/// Creates a DateTime from the given number of seconds since the epoch (1970-01-01T00:00:00Z)
/// </summary>
/// <param name="seconds">seconds since the epoch</param>
/// <returns></returns>
public static DateTime FromEpochSeconds(long seconds)
{
return FromEpochMilliseconds(seconds * 1000);
}
}
}