C# 時間與時間戳互轉 13位|13位時間戳與日期換轉


這里直接上代碼

懂C# 的程序猿 一看便知道如何使用的...

 /// <summary>
/// 將Unix時間戳轉換為DateTime類型時間
/// </summary>
/// <param name="d">double 型數字</param>
/// <returns>DateTime</returns>
public static System.DateTime ConvertIntDateTime(double d)
{
System.DateTime time = System.DateTime.MinValue;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
time = startTime.AddMilliseconds(d);
return time;
}
/// <summary>
/// 將c# DateTime時間格式轉換為Unix時間戳格式
/// </summary>
/// <param name="time">時間</param>
/// <returns>long</returns>
public static long ConvertDateTimeInt(System.DateTime time)
{
//double intResult = 0;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970,1,1,0,0,0,0));
//intResult = (time- startTime).TotalMilliseconds;
long t = (time.Ticks - startTime.Ticks)/10000; //除10000調整為13位
return t;
}

本文轉自:http://yfnk.net/a/wenzhangzhongxin/2013/0415/22.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM