html5中文学习网

您的位置: 首页 > 网络编程 > ASP编程 » 正文

内置函数datediff的妙用_ASP教程_编程技术

[ ] 已经帮助:人解决问题
vb中有许多内置的函数都是非常实用,非常棒的,本文就针对datediff来进行介绍!

1、函数作用:mywHTML5中文学习网 - HTML5先行者学习网

返回两个日期之间的时间间隔。mywHTML5中文学习网 - HTML5先行者学习网

举例:mywHTML5中文学习网 - HTML5先行者学习网

DateDiff("d", Now, theDate)mywHTML5中文学习网 - HTML5先行者学习网

d代表天(日) now 是当前时间, theDate 就是我们自己定义的一个时间mywHTML5中文学习网 - HTML5先行者学习网

那么,整个函数的结果就是自定义时间与当前时间的日期差。mywHTML5中文学习网 - HTML5先行者学习网

(顺便将常用的列举一下,s秒、m分钟、h小时、d日、n月、y年)mywHTML5中文学习网 - HTML5先行者学习网

根据这个函数,我们来制作一个发布时间,显示为多久前的效果mywHTML5中文学习网 - HTML5先行者学习网

<%

limit=DateDiff("s","2009-1-17 9:05:35","2009-1-17 10:05:55")
response.Write  limit&"秒"
response.Write  ("<hr>")

if (limit < 60) then   show_t = "刚刚"
if (limit >= 60 and limit < 3600) then  show_t = INT(limit/60) &"分钟前"
if (limit >= 3600 and limit < 86400) then   show_t = INT(limit/3600) &"小时前"
if (limit >= 86400 and limit < 2592000) then   show_t = INT(limit/86400) &"天前"
if (limit >= 2592000 and limit < 31104000) then   show_t = INT(limit/2592000)  &"个月前"
if limit >= 31104000 then  show_t = "很久很久前.....一只大灰狼......"
response.Write  (show_t)
%>
mywHTML5中文学习网 - HTML5先行者学习网

mywHTML5中文学习网 - HTML5先行者学习网
mywHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助