發布時間:2020-11-30 09:47 作者:獨孤劍 閱讀:1278
using System; namespace ConsoleApp13 { class Program { static void Main(string[] args) { // 1596865604 Console.WriteLine(GetUnixTime(DateTime.Now)); Console.Read(); } /// <summary> /// 獲取Unix時間戳, 秒級 /// </summary> /// <param name="dateTime">時間</param> /// <returns></returns> public static long GetUnixTime(DateTime dateTime) { DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0)); return (long)(dateTime - start).TotalSeconds; } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞