CSharp examples for System:DateTime Unix
To Unix Time
using System.Globalization; using System.Diagnostics.Contracts; using System.Diagnostics.CodeAnalysis; using System;/*from ww w . j av a2 s .c o m*/ public class Main{ public static string ToUnixTime(DateTime dateTime) { if (dateTime < BaseUtcDateTime) { throw new ArgumentException("Date time cannot be less than 01/01/1970."); } Contract.EndContractBlock(); DateTime epoch = BaseUtcDateTime; TimeSpan range = dateTime - epoch; return Math.Floor(range.TotalSeconds).ToString(CultureInfo.InvariantCulture); } }