|
我的asp学习笔记2-Date/Time Functions (VBScript) |
Author:咖啡虫 PublishTime:2004-6-15 |
1.Date and time
<html>
<body>
Today's date is: <%response.write(date())%>.
The server's local time is: <%response.write(time())%>.
</body>
</html>
2.Get the name of a day
<html>
<body>
VBScripts' function [b]WeekdayName[/b] is used to get a weekday:
<%
response.Write(WeekDayName(1))
response.Write("
")
response.Write(WeekDayName(2))
%>
Abbreviated name of a weekday:
<%
response.Write(WeekDayName(1,true))
response.Write("
")
response.Write(WeekDayName(2,true))
%>
Current weekday:
<%
response.Write(WeekdayName(weekday(date)))
response.Write("
")
response.Write(WeekdayName(weekday(date), true))
%>
</body>
</html>
3.Get the name of a month
<html>
<body>
VBScripts' function [b]MonthName[/b] is used to get a month:
<%
response.Write(MonthName(1))
response.Write("
")
response.Write(MonthName(2))
%>
Abbreviated name of a month:
<%
response.Write(MonthName(1,true))
response.Write("
")
response.Write(MonthName(2,true))
%>
Current month:
<%
response.Write(MonthName(month(date)))
response.Write("
")
response.Write(MonthName(month(date), true))
%>
</body>
</html>
4.Get todays' day and month
<html>
<body>
Today it is
<%response.write(WeekdayName(weekday(date)))%>,
<br />
and the month is
<%response.write(MonthName(month(date)))%>
</body>
</html>
5.Countdown to year 3000
<html>
<body>
Countdown to year 3000:
<%millennium=cdate("1/1/3000 00:00:00")%>
It is
<%response.write(DateDiff("yyyy", Now(), millennium))%>
years to year 3000!
It is
<%response.write(DateDiff("m", Now(), millennium))%>
months to year 3000!
It is
<%response.write(DateDiff("ww", Now(), millennium))%>
weeks to year 3000!
It is
<%response.write(DateDiff("d", Now(), millennium))%>
days to year 3000!
It is
<%response.write(DateDiff("h", Now(), millennium))%>
hours to year 3000!
It is
<%response.write(DateDiff("n", Now(), millennium))%>
minutes to year 3000!
It is
<%response.write(DateDiff("s", Now(), millennium))%>
seconds to year 3000!
</body>
</html>
6.Calculate a day x days from today
<html>
<body>
<%
response.write(DateAdd("d",30,date()))
%>
Syntax for DateAdd: DateAdd(interval,number,date). You can use [b]DateAdd[/b] to for example calculate a date 30 days from today.
</body>
</html>
7.Format date and time
<html>
<body>
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br />")
response.write(FormatDateTime(date(),vblongdate))
response.write("<br />")
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br />")
response.write(FormatDateTime(now(),vblongtime))
response.write("<br />")
response.write(FormatDateTime(now(),vbshorttime))
%>
Syntax for FormatDateTime: FormatDateTime(date,namedformat).
</body>
</html>
8.Is this a date?
<html>
<body>
<%
somedate="10/30/99"
response.write(IsDate(somedate))
%>
</body>
</html>
|
| | |