mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
feat: add methods for creating a DateTime from epoch seconds or millis
This commit is contained in:
parent
13d1072d10
commit
0b8eb82e3b
1 changed files with 23 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue