因此對應到 .Net 上必須轉換,這樣搜尋時才會 locate 到正確的時間點
參考資料: http://www.snippetit.com/2009/04/c-unix-time-to-net-datetime-and-vice-versa/
using System; namespace snippetit.sample { struct UnixTime { private static DateTime BEGIN_UTC = new DateTime(1970, 1, 1); private long utValue; public UnixTime(long seconds) { utValue = seconds; } public UnixTime(DateTime dateTime) { this.DateTime = dateTime; } public long Value { get { return utValue; } set { utValue = value; } } public DateTime DateTime { get { return BEGIN_UTC.AddSeconds((long)utValue); } set { utValue = (long)((TimeSpan)(value - BEGIN_UTC)).TotalSeconds; } } public override string ToString() { return DateTime.ToString("yyy-MM-dd HH:mm:ss"); ; } } }
將 UnixTime 轉成 long: http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Convert-Unix-timestamp.html
No comments:
Post a Comment