VBScript日期函数处理

来源:互联网 发布:湖南用友软件代理商 编辑:程序博客网 时间:2024/05/16 06:12
VBScript日期函数处理
名称语法功能例句
CDateCDate(date)返回date类型的表达式,date 参数是任意有效的日期或字符串表达式。MyDate = "October 19, 1962" MyShortDate = CDate(MyDate)
DateDate返回当前系统日期。不带()MyDate = Date
DateAddDateAdd(interval, number, date) 返回已添加指定时间间隔的日期。下例将95 年1 月31 日加上一 个月:
NewDate =
DateAdd(
"m", 1, "31-Jan-95")
DateDiffDateDiff(interval,date1, date2)  返回两个日期之间的时间间隔。xx= DateDiff("d", Now, theDate)
DatePartDatePart(interval, date)返回给定日期的指定部分。参考interval参数的可选值。GetQuarter =
    DatePart(
"q", TheDate)
DateSerialDateSerial(year, month, day) 对于指定的年、月、日,返回 Date 子类型的 Variant。MyDate2 =
DateSerial(
1990-10, 8-2, 1)
DateValueDateValue(date)返回 Date 子类型的变量。date 参数应是字符串。DateValue("September 11, 1963")
DayDay(date)返回1 到 31 之间的一个整数,代表某月中的一天。MyDay = Day("October 19, 1962") 'MyDay =19。
HourHour(Time)返回0到23之间的一个整数,代表某小时数。Time参数是时间表达式。MyTime = Now
MyHour = Hour(MyTime)
IsDateIsDate(expression)返回Boolean值指明某表达式是否可以转换为日期。expression 参数可以是任意可被识别为日期和时间的日期表达式或字符串表达式。MyDate = "October 19, 1962" YourDate = #10/19/62#
NoDate = "Hello"
MyCheck= IsDate(MyDate) 'True MyCheck= IsDate(YourDate)'True MyCheck= IsDate(NoDate) 'False
MinuteMinute(Time)返回0到59之间的整数,代表分钟。MyVar = Minute(Now) '=41
MonthMonth(date)返回 1到12 之间的一个整数,代表某月份数。MyVar=Minute("October 19, 1962")
'MyVar = 10
MonthNameMonthName(month)返回表明指定月份的字符串。month是数值thismanth = MonthName(10)'
’thismanth = "October"
NowNow返回系统的当前日期和时间值。Today = Now
' today = "02-07-04 11:41:14"
SecondSecond(Time) 返回 0到 59之间的一个整数,代表某秒数。MySec = Second(Now)
'
MySec =14
TimeTime返回当前的系统时间。
MyTime = Time
'
MyTime = "11:41:14"
TimerTimer返回午夜 12 时以后已经过去的秒数。
TimeSerialTimeSerial(h,m,s)返回含有指定时h、分m、秒s的时间。MyTime1 = TimeSerial(12-6,-15,0)
' 返回 "5:45:00 AM."
TimeValueTimeValue(time)返回包含时间的 Date子类型的变量。
time 参数通常是代表时间表达式。
MyTime = TimeValue("4:35:17 PM")
WeekdayWeekday(date)返回代表一星期中某天的整数0到6。MyDate = #October 19, 1962#
MyWeekDay = Weekday(MyDate)
WeekdayNameWeekdayName(weekday)返回指定某天是星期几的字符串。MyDate= WeekDayName(1)'Sunday
YearYear(date)返回一个代表某年的整数。MyYear = Year(now) '2002
FormatDateTimeFormatDateTime(Date[, NamedFormat])返回表达式,此表达式已被格式化为日期或时间。NamedFormat=0,1,2,3,4GetCurrentDate =
    
FormatDateTime(Date, 1)

上表的语法格式中没有括号的表示无参数,date和time分别表示日期类型和时间类型的参数。

部分日期时间型函数用法举例。

关键字 日期时间型函数

代码

dim today, mydate, mytime
Sub print(x)
x = "<FONT color=red>" &x
x = x &"</FONT>"
document.write (x)
End sub
document.write "<FONT size=4><p align ='center'>"
document.write "VB部分日期时间型函数用法举例"
document.write "</FONT></P>"
today = date
document.write "Today is "
print today
document.write "<br>"
document.write "变量today 的类型是" &TypeName(today) &"<BR>"
document.write "今天是"
print year(date) &"年"
print MonthName(Month(date))
print day(date)
print "日<br>"
document.write "用格式化函数FormatDateTime(x,1)转换的日期是"
print formatDateTime(date,1) &"<BR>"
if ( Now = date& time) then
print "NOW=DATE + TIME<BR>"
else
print "NOW包含DATE 和 TIME<BR>"
end if
document.write "今天是星期几?<BR>"
print "今天是" & WeekdayName(weekday(date)) &"<BR>"
print "今天是星期" & weekday(date)-1 &"<BR>"
today ="march, 21,1994"
Mydate = Cdate(today)
print mydate&"<BR>"
birthday= DateSerial(1994,3,21)
document.write "我的生日是" & birthday&","
num = DateDiff("w", birthday,date)
print "那您已经过了" & num &"周<BR>"
Mydata = DateAdd("d",1,date)
Print "明天是" &FormatDateTime(Mydata,1)
print DateValue("1989-6-4")
print #1989-6-4#-1 & "<BR>"
document.write "What time it is Now ? "
print "Time is " & Time & "<BR>"
document.write "What time it is HOUR ? "
print "Hour in " & Hour(Time) & "<BR>"
document.write "What time it is Minute?"
print "Minute is " & Minute(Time) & "<BR>"
document.write "What time it is Second?"
print "Second is " & Second(Time) & "<BR>"
MyTime = TimeSerial(12-6,15,10)
print Mytime& "<BR>"
document.write "今天是在第"
print DatePart("q",date)
document.write "季度<p>"
document.write"<Font size =4>再见</Font>"

阅读(1429) | 评论(0) | 转发(0) |
0

上一篇:使用Office自动的软件将图片中的文字信息转换成word文档

下一篇:checkbox,select,radio 选取值,设定值,回显值

相关热门文章
  • 类的设计原则:单一职责SPR、...
  • 加拿大移民代理都有哪些服务项...
  • 优惠/靓机HP4286A HP4286A HP4...
  • 加拿大BC省提名项目更具优势...
  • 大数据如日中天,您中暑了吗?...
  • JDK1.6官方下载_JDK6官方下载_...
  • MyEclipse6.5下载及注册码...
  • Eclipse+MyEclipse的配置
  • Eclipse 插件安装、升级和卸载...
  • 最新版SWT Designer 6.0 安装,...
  • flash播放控件
  • 查看nginx某一时段的日志...
  • ftp服务器日志分析
  • mpi 目标机器积极拒绝,下面错...
  • ps700 安装的aix6.1以后,装上...
给主人留下些什么吧!~~
原创粉丝点击