get Unix UTC Time From Utc Date Time - CSharp System

CSharp examples for System:DateTime Unix

Description

get Unix UTC Time From Utc Date Time

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w ww.j a v a2  s. c o  m*/

public class Main{
        public static long getUnixUTCTimeFromUtcDateTime(DateTime utcTime)
        {
            //create Timespan by subtracting the value provided from the Unix Epoch
            TimeSpan span = (utcTime - new DateTime(1970, 1, 1, 0, 0, 0, 0));

            //return the total seconds (which is a UNIX timestamp)
            return (long)span.TotalSeconds;
        }
}

Related Tutorials