C#常用类库
2024-10-12 16:47:04
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秒后会从数据库中重新获取。
}
最新文章
- JAVA Shallow heap &; Retained heap
- 使用BBED模拟Oracle数据库坏块
- Strip JS – 低侵入,响应式的 Lightbox 效果
- OpenSSL命令---pkcs7
- 统计图表--第三方开源--MPAndroidChart(一)
- springmvc环境的搭建
- Mysql数据库导出压缩并保存到指定位置备份脚本
- Spring-data-redis操作redis cluster
- C#读取word内容实践
- 洛谷P3975 弦论
- js判断手机邮箱格式(正则)
- Swing的特性
- CentOS7_JDK安装和环境变量配置
- 2016ICPC-大连 A Simple Math Problem (数学)
- [WPF]解决模板中ContextMenu绑定CommandParameter的问题
- ListView高效分页
- django 连接mysql 数据库
- 【安装Python环境】之安装Selenium2时报UnicodeDecodeError: &#39;utf-8&#39; codec can&#39;t decode byte 0xc8 in position 12: invalid continuation byte问题
- python:利用smtplib模块发送邮件详解
- 20135320赵瀚青LINUX第六周学习笔记