Get Unix Timestamp From Local Time - CSharp System

CSharp examples for System:DateTime Unix

Description

Get Unix Timestamp From Local Time

Demo Code


using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/*from   www  . j a v a  2  s  .  com*/

public class Main{
        public static string GetUnixTimestampFromLocalTime(DateTime? dt=null)
        {
            if(dt==null)
            {
                dt=DateTime.Now;
            }
            DateTime basetime= new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Math.Floor((dt.Value.ToUniversalTime()-basetime).TotalSeconds).ToString();
        }
}

Related Tutorials