public static double ToUnixTimestamp(this DateTime value) { // create Timespan by subtracting the value provided from the Unix Epoch TimeSpan span = value - UnixEpoh.Create(); // return the total seconds (which is a UNIX timestamp) return(span.TotalSeconds); }
public static DateTime FromUnixTimestamp(this string value) { if (string.IsNullOrWhiteSpace(value)) { return(DateTime.MinValue); } double totalSeconds; if (!double.TryParse(value, out totalSeconds)) { return(DateTime.MinValue); } var timeSpan = TimeSpan.FromSeconds(totalSeconds); return(UnixEpoh.Create().Add(timeSpan)); }