CSharp examples for System:DateTime Unix
Converts a datetime object to unix format depending in the chosen type (Milliseconds|Seconds)
using System.Text; using System.Linq; using System.Collections.Generic; using System;//from ww w. j ava 2 s .c om public class Main{ /// <summary> /// Converts a datetime object to unix format depending in /// the chosen type (Milliseconds|Seconds) /// </summary> /// <param name="dateTime">DateTime object to be converted</param> /// <param name="type">Type of the value to be retrieved</param> /// <returns></returns> public static long DateTimeToUnixTime(DateTime dateTime, UnixTimeType type) { TimeSpan timeSpan = dateTime - EPOCH; if (type == UnixTimeType.Milliseconds) { return (long)timeSpan.TotalMilliseconds; } else { return (long)timeSpan.TotalSeconds; } } }