Convert Date Time to Unix Timestamp and Vice Versa (seconds or milliseconds format)
using SG.UnixTime;
example 1 :
DateTime currentDateTime = DateTime.Now;
Int32 epoch = 0;
epoch = UnixTime.ToEpoch(currentDateTime);
Console.WriteLine(epoch);
example 2 (to seconds with inferred type) :
DateTime currentDateTime = DateTime.Now;
Int32 epoch = 0;
epoch = UnixTime.ToEpoch<Int32>(currentDateTime, ConvertFormat.ToSeconds);
Console.WriteLine(epoch);
example 3 (to milliseconds with inferred type) :
DateTime currentDateTime = DateTime.Now;
long epoch = 0;
epoch = UnixTime.ToEpoch<long>(currentDateTime, ConvertFormat.ToMilliseconds);
Console.WriteLine(epoch);
example 1 :
DateTime defaultTime = DateTime.Now;
defaultTime = UnixTime.ToDateTime(epoch);
Console.WriteLine(defaultTime);
example 2 :
DateTime defaultTime = DateTime.Now;
defaultTime = UnixTime.ToDateTime<Int32>(epoch, ConvertFormat.ToSeconds);
Console.WriteLine(defaultTime);
example 3 :
DateTime defaultTime = DateTime.Now;
defaultTime = UnixTime.ToDateTime <long>(epoch, ConvertFormat.ToMilliseconds);
Console.WriteLine(defaultTime);
Int32 epoch = 0;
epoch = UnixTime.ToEpoch<Int32>(currentDateTime, ConvertFormat.ToSeconds);
int seconds = 10;
Int32 addSeconds = UnixTime.AddSeconds(epoch, seconds);
Int32 epoch = 0;
epoch = UnixTime.ToEpoch<Int32>(currentDateTime, ConvertFormat.ToSeconds);
int milliseconds = 2000;
Int32 addmilliseconds = UnixTime.AddMilliseconds(epoch, milliseconds);