Unixtime Functions

private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); /// <summary> /// Converts unixtime stamp to DateTime /// </summary> /// <param name="unixtime">unixtime stamp as string</param> /// <returns>DateTime</returns> public static DateTime UnixTimeToDateTime(string unixtime) { double seconds = double.Parse(unixtime, CultureInfo.InvariantCulture); return Epoch.AddSeconds(seconds); } /// <summary> /// Returns current unixtime stamp /// </summary> /// <returns>string unixtime</returns> public static string UnixTimeNow() { return ((Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(); }
Basic c# functions to return the current unixtime stamp and to convert unixtime stamp to a DateTime.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.