如何在asp里格式化当前时间

成功代码:<%
mm=now()
month2=month(mm)
if len(month2)=1 then
month2="0"&month2
end if
day2=day(mm)
if len(day2)=1 then
day2="0"&day2
end if
Response.write(year(mm)&"-"&month2&"-"&day2)
%>
在asp里格式化当前时间now,格式是'yyyymmddhhnnss',希望方法简短,不要采用datepart进行逐段取下连接,或用year(),month()等取下连接。 
 
FormatDateTime  函数 
请参阅 
FormatCurrency  函数    |  FormatNumber  函数    |  FormatPercent  函数 
要求 
版本2 
返回表达式,此表达式已被格式化为日期或时间。 
 
FormatDateTime(Date[,  NamedFormat]) 
参数 
Date   
必选项。要被格式化的日期表达式。   
NamedFormat   
可选项。指示所使用的日期/时间格式的数值,如果省略,则使用  vbGeneralDate。   
设置 
NamedFormat  参数可以有以下值: 
 
常数  值  描述   
vbGeneralDate  0  显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示所有部分。   
vbLongDate  1  使用计算机区域设置中指定的长日期格式显示日期。   
vbShortDate  2  使用计算机区域设置中指定的短日期格式显示日期。   
vbLongTime  3  使用计算机区域设置中指定的时间格式显示时间。   
vbShortTime  4  使用  24  小时格式  (hh:mm)  显示时间。   
 
说明 
下面例子利用  FormatDateTime  函数把表达式格式化为长日期型并且把它赋给  MyDateTime:   
 
Function  GetCurrentDate   
     'FormatDateTime  把日期型格式化为长日期型。 
     GetCurrentDate  =  FormatDateTime(Date,  1)   
End  Function 
 
sub  FormatDT(birth)                                  '日期格式化函数 
       birth      =  formatdatetime(birth,2) 
       enyear    =  CStr(year(birth)) 
       enmonth  =  month(birth) 
       enday      =  day(birth) 
       if  len(CInt(enmonth))=1  then 
           enmonth="0"&CStr(enmonth) 
       end  if 
       if  len(CInt(enday))=1  then 
           enday="0"&CStr(enday) 
       end  if 
       birth_no=enyear&"-"&enmonth&"-"&enday 
   end  sub 
--------------------------------------------------------------- 
 
FormatDateTime  函数 
请参阅 
FormatCurrency  函数    |  FormatNumber  函数    |  FormatPercent  函数 
要求 
版本2 
返回表达式,此表达式已被格式化为日期或时间。 
 
FormatDateTime(Date[,  NamedFormat]) 
参数 
Date   
必选项。要被格式化的日期表达式。   
NamedFormat   
可选项。指示所使用的日期/时间格式的数值,如果省略,则使用  vbGeneralDate。   
设置 
NamedFormat  参数可以有以下值: 
 
常数  值  描述   
vbGeneralDate  0  显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示所有部分。   
vbLongDate  1  使用计算机区域设置中指定的长日期格式显示日期。   
vbShortDate  2  使用计算机区域设置中指定的短日期格式显示日期。   
vbLongTime  3  使用计算机区域设置中指定的时间格式显示时间。   
vbShortTime  4  使用  24  小时格式  (hh:mm)  显示时间。   
 
说明 
下面例子利用  FormatDateTime  函数把表达式格式化为长日期型并且把它赋给  MyDateTime:   
 
Function  GetCurrentDate   
     'FormatDateTime  把日期型格式化为长日期型。 
     GetCurrentDate  =  FormatDateTime(Date,  1)   
End  Function 
 
mm表示一个日期 
year(mm)&"-"&month(mm)&"-"&day(mm)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值