当前位置:首页 > Windows程序 > 正文

C#unix时间戳转换

2021-05-26 Windows程序

标签:

/// <summary> /// 日期转换成unix时间戳 /// </summary> /// <param></param> /// <returns></returns> public static long DateTimeToUnixTimestamp(DateTime dateTime) { var start = new DateTime(1970, 1, 1, 0, 0, 0, dateTime.Kind); return Convert.ToInt64((dateTime - start).TotalSeconds); } /// <summary> /// unix时间戳转换成日期 /// </summary> /// <param>时间戳(秒)</param> /// <returns></returns> public static DateTime UnixTimestampToDateTime(this DateTime target, long timestamp) { var start = new DateTime(1970, 1, 1, 0, 0, 0, target.Kind); return start.AddSeconds(timestamp); }

标签:

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/71583.html