Generate a Unix Timestamp in C#
This code will allow you to generate a unix timestamp for a given DateTime, turn a unix timestamp back into a DateTime, or get the current unix timestamp.
64-bit version (future proof)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XeonProductions
{
static class UnixTimestamp
{
public static DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);
public static ulong DateTimeToUnixTimestamp(DateTime time)
{
return (ulong)(time - UnixEpoch).TotalSeconds;
}
public static DateTime UnixTimestampToDateTime(ulong timestamp)
{
return UnixEpoch.AddSeconds(timestamp);
}
public static ulong Now
{
get
{
return (ulong)(DateTime.UtcNow - UnixEpoch).TotalSeconds;
}
}
}
}
32-bit signed version
using System;
using

