标签:
制作时间戳:
/// <summary>
/// DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time"> DateTime时间格式</param>
/// <returns>Unix时间戳格式</returns>
public static long ConvertDateTimeInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (long)(time - startTime).TotalSeconds;
}
调用方法: long time = ConvertDateTimeInt(DateTime.Now);
时间戳转标准时间:
private string GetTime(string timeStamp) { DateTime dt = DateTime.Now; if (timeStamp.Length == 14) { dt = DateTime.ParseExact(timeStamp, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); } return dt.ToString("yyyy-MM-dd HH:mm:ss"); }
调用方法:var datetime = GetTime(transactionTime);
标签:
原文地址:http://www.cnblogs.com/yonguibe/p/4448345.html