代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
ASP.NET设置发帖时间间隔不超过30秒
作者:
Dezai.CN
/ 发布于
2012/10/25
/
617
ASP.NET设置发帖时间间隔不超过30秒
<div>大气象</div> <div></div> <div></div> <div></div> <div>Code highlighting produced by Actipro CodeHighlighter (freeware)</div> <div>http://www.CodeHighlighter.com/</div> <div></div> <div>-->protected void btnPost_Click(object sender, EventArgs e)</div> <div>{</div> <div> if (Session["lastTime"] == null)</div> <div> {</div> <div> Session["lastTime"] = DateTime.Now;</div> <div> } <div> DateTime dt = Convert.ToDateTime(Session["lastTime"]);</div> <div> TimeSpan ts = DateTime.Now - dt;</div> <div> Response.Write(ts.Days + ":" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds);</div> <div> if (ts.Hours > 0 || ts.Minutes > 0 || ts.Seconds > 30)</div> <div> {</div> <div> Session["lastTime"] = DateTime.Now;</div> <div> Response.Write("可以发帖!");</div> <div> } <div> else</div> <div> {</div> <div> Response.Write("你的发帖速度过快!时间间隔不要小于30秒!");</div> <div> } <div>} <div>/// <summary></div> <div>/// 把秒转换成分钟</div> <div>/// </summary></div> <div>/// <returns></returns></div> <div>public static int SecondToMinute(int Second)</div> <div>{</div> <div> decimal mm = (decimal)((decimal)Second / (decimal)60);</div> <div> return Convert.ToInt32(Math.Ceiling(mm));</div> <div>} <div>/// <summary></div> <div>/// 计算两个时间的时间间隔</div> <div>/// </summary></div> <div>/// <param name="DateTimeOld">较早的日期和时间</param></div> <div>/// <param name="DateTimeNew">较后的日期和时间</param></div> <div>/// <returns></returns></div> <div>public static string DateDiff(DateTime DateTimeOld, DateTime DateTimeNew)</div> <div>{</div> <div> string dateDiff = "";</div> <div> TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);</div> <div> TimeSpan ts2 = new TimeSpan(DateTimeNew.Ticks);</div> <div> TimeSpan ts = ts1.Subtract(ts2).Duration();</div> <div> int day = ts.Days;</div> <div> int hou = ts.Hours;</div> <div> int minu = ts.Minutes;</div> <div> int sec = ts.Seconds;</div> <div> if (day > 0)</div> <div> {</div> <div> if (day > 30)</div> <div> {</div> <div> if (day > 364)</div> <div> {</div> <div> dateDiff += day / 365 + "年";</div> <div> } <div> else</div> <div> {</div> <div> dateDiff += day / 30 + "个月";</div> <div> } <div> } <div> else</div> <div> {</div> <div> dateDiff += day.ToString() + "天";</div> <div> } <div> } <div> else</div> <div> {</div> <div> if (hou > 0)</div> <div> {</div> <div> dateDiff += hou.ToString() + "小时";</div> <div> } <div> else</div> <div> {</div> <div> if (minu > 0)</div> <div> {</div> <div> dateDiff += minu.ToString() + "分钟";</div> <div> } <div> else</div> <div> {</div> <div> if (sec > 0)</div> <div> {</div> <div> dateDiff += sec.ToString() + "秒";</div> <div> } <div> else</div> <div> {</div> <div> dateDiff += "0秒";</div> <div> } <div> } <div> } <div> } <div> if (DateTimeNew.CompareTo(DateTimeOld) > 0)</div> <div> {</div> <div> dateDiff += "前";</div> <div> } <div> else</div> <div> {</div> <div> dateDiff += "后";</div> <div> } <div> return dateDiff;</div> <div>} <div>/// <summary></div> <div>///判断是否于5分钟之前</div> <div>/// </summary></div> <div>/// <param name="DateTimeOld">较早的日期和时间</param></div> <div>/// <returns></returns></div> <div>public static bool DateDiff_minu(DateTime DateTimeOld)</div> <div>{</div> <div> TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);</div> <div> TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);</div> <div> TimeSpan ts = ts1.Subtract(ts2).Duration();</div> <div> int minu = ts.Minutes;</div> <div> if (minu > 5)</div> <div> {</div> <div> return true;</div> <div> } <div> else</div> <div> {</div> <div> return false;</div> <div> } <div>} <div>/// <summary></div> <div>/// 与当前时间比较,重载时间比较函数,只有一个参数</div> <div>/// </summary></div> <div>/// <param name="DateTimeOld">较早的日期和时间</param></div> <div>/// <returns></returns></div> <div>public static string DateDiff(DateTime DateTimeOld)</div> <div>{</div> <div> return DateDiff(DateTimeOld, DateTime.Now);</div> <div>} <div>/// <summary></div> <div>/// 日期比较,返回精确的几分几秒</div> <div>/// </summary></div> <div>/// <param name="DateTime1">较早的日期和时间</param></div> <div>/// <param name="DateTime2">较迟的日期和时间</param></div> <div>/// <returns></returns></div> <div>public static string DateDiff_full(DateTime DateTime1, DateTime DateTime2)</div> <div>{</div> <div> string dateDiff = null;</div> <div> TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);</div> <div> TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);</div> <div> TimeSpan ts = ts1.Subtract(ts2).Duration();</div> <div> dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";</div> <div> return dateDiff;</div> <div>} <div>/// <summary></div> <div>/// 时间比较,返回精确的几秒</div> <div>/// </summary></div> <div>/// <param name="DateTime1">较早的日期和时间</param></div> <div>/// <param name="DateTime2">较迟的日期和时间</param></div> <div>/// <returns></returns></div> <div>public static int DateDiff_Sec(DateTime DateTime1, DateTime DateTime2)</div> <div>{</div> <div> TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);</div> <div> TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);</div> <div> TimeSpan ts = ts1.Subtract(ts2).Duration();</div> <div> int dateDiff = ts.Days * 86400 + ts.Hours * 3600 + ts.Minutes * 60 + ts.Seconds;</div> <div> return dateDiff;</div> <div>} <div></div> <div></div> <div>/// <summary></div> <div>/// 日期比较</div> <div>/// </summary></div> <div>/// <param name="today">当前日期</param></div> <div>/// <param name="writeDate">输入日期</param></div> <div>/// <param name="n">比较天数</param></div> <div>/// <returns>大于天数返回true,小于返回false</returns></div> <div>public static bool CompareDate(string today, string writeDate, int n)</div> <div>{</div> <div> DateTime Today = Convert.ToDateTime(today);</div> <div> DateTime WriteDate = Convert.ToDateTime(writeDate);</div> <div> WriteDate = WriteDate.AddDays(n);</div> <div> if (Today >= WriteDate)</div> <div> return false;</div> <div> else</div> <div> return true;</div> <div>}
试试其它关键字
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3