ASP倒计时
2012-08-31 金城 7895
ASP倒计时代码 [演示]
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%
response.Charset="utf-8"
dim destination : destination=#2012-12-21 0:0:0# '' 定义目标时间
dim N : N=now() '' 定格页面打开的时刻,以此计算
dim dd,hh,mm,ss,S
S=datediff("s",N,destination) '' 得出秒差(精确到秒)
dd=S \ (24*3600) '' 天数取整,不足一天不计算在内
hh=(S \ 3600) mod 24 '' 小时取余
mm=(S\60) mod 60 '' 分钟取余
ss=S mod 60 '' 秒数取余
response.Write "距离 <strong>" & destination & "</strong> 倒计时<br/><strong>" & dd & "</strong>天<strong>" & hh & "</strong>时<strong>"& mm &"</strong>分<strong>" & ss & "</strong>秒<br/>共计"& S &"秒"
%>
response.Charset="utf-8"
dim destination : destination=#2012-12-21 0:0:0# '' 定义目标时间
dim N : N=now() '' 定格页面打开的时刻,以此计算
dim dd,hh,mm,ss,S
S=datediff("s",N,destination) '' 得出秒差(精确到秒)
dd=S \ (24*3600) '' 天数取整,不足一天不计算在内
hh=(S \ 3600) mod 24 '' 小时取余
mm=(S\60) mod 60 '' 分钟取余
ss=S mod 60 '' 秒数取余
response.Write "距离 <strong>" & destination & "</strong> 倒计时<br/><strong>" & dd & "</strong>天<strong>" & hh & "</strong>时<strong>"& mm &"</strong>分<strong>" & ss & "</strong>秒<br/>共计"& S &"秒"
%>
天时分秒等,不能光用 datediff 函数取得,因为这个函数将不足一个单位的按一个单位算。 取余数就可以了。
"\" 整除运算符
mod 取余(求模和取余在VB里是一个概念,某些语言里不一样,如JAVA中略有差异。)