This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTS.Common.Utilities
{
/// <summary>
/// Convert a DateTime to Unix Time. No attempt is made to correct for time zone/localities.
/// </summary>
public class Time
{
public static UInt32 DateTimeToUnixTimestamp(DateTime dateTime)
{
var start = new DateTime(1970, 1, 1);
var span = dateTime - start;
return (UInt32)span.TotalSeconds;
}
public static UInt32 CurrentUtcUnixTimestamp()
{
var span = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
return (UInt32)span.TotalSeconds;
}
public static UInt32 CurrentLocalUnixTimestamp()
{
var span = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local));
return (UInt32)span.TotalSeconds;
}
public static DateTime ToDateTime(UInt32 seconds)
{
return new DateTime(1970, 1, 1).AddSeconds(seconds);
}
public static UInt32 ToUnixTime(DateTime dateTime)
{
var start = new DateTime(1970, 1, 1);
var span = dateTime - start;
return (UInt32)span.TotalSeconds;
}
public static bool IsBeginningOfTime(DateTime dateTime)
{
var start = new DateTime(1970, 1, 1);
var span = dateTime - start;
return (0 == span.TotalSeconds);
}
}
}