發現目前大多數日期都是數字,查了一下是Unix Timestamp
寫了兩個Function來互轉
時間轉數字
public static double DateToDouble(DateTime? pNow = null) { DateTime mNow = DateTime.Now; if (pNow != null && pNow.HasValue) { mNow = pNow.Value; } DateTimeOffset t = DateTimeOffset.Parse(mNow.ToString("yyyy-MM-dd HH:mm:ss")); return Convert.ToDouble(t.ToUnixTimeSeconds()); }數字轉時間
public static DateTime DoubleToDate(double? pDate = 0) { double d = 0; if (pDate != null && pDate.HasValue) { d = pDate.Value; } if (d > 9999999999) d = d / 1000; DateTime StartComputerFirstDay = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); return StartComputerFirstDay.AddSeconds(d).ToLocalTime(); }參考資料
[C#] 時間轉換為Unix TimeStamp
Epoch (computing)
The Current Epoch Unix Timestamp