高中英语选修6课件ppt:关于ASP中的时间的问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/05 00:07:58
<% if Time<=#12:00:00 AM# and Time>#12:00:00 PM# then%>
早上好!
<% else %>
Hello!
<% end if %>
我在下午调试上面这个程序,输出“Hello!”
我又将此程序改成:
<% if Time>=#12:00:00 AM# and Time<#12:00:00 PM# then%>'两个关系运算符变了
早上好!
<% else %>
Hello!
<% end if %>
可是还是输出“Hello!”
请问这是怎么回事?ASP中的时间比较(例如>#12:00 AM# <=#8:00:00pm#)究竟是怎么判断的?

你用time取出来的是字符串,结果和字符串比较会出现2大于1也大于12(还有10、11)的问题。

应该用hour取出小时,再和12比较:

<%
nowhour = hour(time)
if nowhour>0 and nowhour<12 then
greeting="早上好"
else
greeting="Hello"
end if
%>

明白了嘛?

你可以输入如下代码:
<body>
<%
if time >=12:00:00 AM and time<=12:00:00pm then
greeting="早上好"
else
greeting="Hello"
end if
%>
<%=greeting%>
</body>
这样应该可以了