Unix epoch time from a datetime - CSharp System

CSharp examples for System:DateTime Unix

Description

Unix epoch time from a datetime

Demo Code


using System;/*from w w  w. j  a  v  a 2  s  .co  m*/

public class Main{
        /// <summary>
        /// Unix epoch time from a datetime
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static long DateTimeToEpochMilliseconds(this DateTimeOffset date)
        {
            var t = (date - new DateTimeOffset(1970, 1, 1,0,0,0,TimeSpan.Zero));
            return (long)t.TotalMilliseconds;
        }
}

Related Tutorials