You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
949 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HuizhongLibrary
{
public static class DateUtils
{
public static long ToTimestamp(this DateTime dateTime)
{
DateTime historyDate = new DateTime(1970, 1, 1);
long timestamp = (dateTime.Ticks - historyDate.Ticks) / 10000000 - 8 * 60 * 60;
return timestamp;
}
public static DateTime ToDateTime(this long timestamp)
{
DateTime historyDate = new DateTime(1970, 1, 1);
long timeTicks = (timestamp + 8 * 60 * 60) * 10000000 + historyDate.Ticks;
return DateTime.FromBinary(timeTicks);
}
/// <summary>
/// 获取北京时间
/// </summary>
/// <returns></returns>
public static DateTime GetBJNow()
{
return DateTime.Now.ToUniversalTime().AddHours(8);
}
}
}