using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace KJD_Web.Utils
{
public class TimeUtils
{
///
/// 时间戳转为C#格式时间
///
///
///
public static DateTime StampToDateTime(int timeStamp)
{
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dateTimeStart.Add(toNow);
}
///
/// 时间戳转为C#格式时间
///
///
///
public static DateTime StampMillisecondsToDateTime(long timeStamp)
{
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000");
TimeSpan toNow = new TimeSpan(lTime);
return dateTimeStart.Add(toNow);
}
///
/// C#格式时间转换为Unix时间戳(秒)
///
///
///
public static int DateTimeToTimestampSeconds(DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}
///
/// C#格式时间转换为Unix时间戳(毫秒)
///
///
///
public static long DateTimeToTimestampMilliseconds(DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (long)(time - startTime).TotalMilliseconds;
}
}
}