1.0 TimeSpan
TimeSpan passTime = (TimeSpan)(DateTime.Now - curUser.refuseTime);
if (passTime.Days * 24 + passTime.Hours < 24)
{
string cs = string.Format("您撤单过后,24小时内不能接单,还要等{0}小时.", 24 - passTime.Hours);
return WriteError(cs);
}
2.0 timestamp 时间戳
public static int ConvertDateTimeInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}
public static int GetTimestamp()
{
return ConvertDateTimeInt(DateTime.Now);
}
3.0 缓存
if (HttpRuntime.Cache["access_token"] == null)
{
HttpRuntime.Cache.Insert("access_token", access_token, null, DateTime.Now.AddSeconds(expires_in - 60), System.Web.Caching.Cache.NoSlidingExpiration); //这里给数据加缓存,设置缓存时间
//"key"为缓存的键,access_token为缓存起来的值,null为缓存依赖项,这里没有使用缓存依赖项,所以为null,
//null后面为缓存的时间为7168秒 最后一个参数为设置时间的格式,ASP.NET允许你设置一个绝对过期时间或滑动过期时间,但不能同时使用,
//我们这里设置的为绝对过期时间,也就是刷新一次页面后缓存数据为7168秒,7168秒后会从数据库中重新获取。
}