如将时间2007-1-1 1:01:01变为2007-01-01 01:01:01,需要将日期格式化,可用如下方法: 
 
一、补零: 
time.asp: 
- <%
 
 - function fordate(date)
 
 -      fordate=year(date)&"-"&right(0&month(date),2)&"-"&right(0&day(date),2)
 
 -      fordate=fordate&" "&right(0&hour(date),2)&":"&right(0&minute(date),2)&":"&right(0&second(date),2)
 
 - end function
 
 - %>
 
  复制代码 
使用方法: 
在要格式化日期的文件中包含time.asp:<!--#include file="time.asp"--> 
输出时间处使用此函数: 
如:<%=rs("dateandtime")%>改为<%=fordate(rs("dateandtime"))%> 
 
二、日期格式化函数 
- function formatdate(strdate,fstr)
 
 -   if isdate(strdate) then
 
 -     dim i,temp
 
 -     temp=replace(fstr,"yyyy",datepart("yyyy",strdate))
 
 -     temp=replace(temp,"yy",mid(datepart("yyyy",strdate),3))
 
 -     temp=replace(temp,"y",datepart("y",strdate))
 
 -     temp=replace(temp,"w",datepart("w",strdate))
 
 -     temp=replace(temp,"ww",datepart("ww",strdate))
 
 -     temp=replace(temp,"q",datepart("q",strdate))
 
 -     temp=replace(temp,"mm",iif(len(datepart("m",strdate))>1,datepart("m",strdate),"0"&datepart("m",strdate)))
 
 -     temp=replace(temp,"dd",iif(len(datepart("d",strdate))>1,datepart("d",strdate),"0"&datepart("d",strdate)))
 
 -     temp=replace(temp,"hh",iif(len(datepart("h",strdate))>1,datepart("h",strdate),"0"&datepart("h",strdate)))
 
 -     temp=replace(temp,"nn",iif(len(datepart("n",strdate))>1,datepart("n",strdate),"0"&datepart("n",strdate)))
 
 -     temp=replace(temp,"ss",iif(len(datepart("s",strdate))>1,datepart("s",strdate),"0"&datepart("s",strdate)))
 
 -     formatdate=temp
 
 -   else
 
 -     formatdate=false
 
 -   end if
 
 - end function
 
  复制代码 
  使用说明: 
  yyyy 长度为4的年 
  yy 长度为2的年 
  q 季  
  mm 月  
  dd 日  
  w 星期几 
  ww 一年中第几个星期 
  hh 时  
  nn 分  
  ss 秒  
 
  例:formatdate(now(),"yyyymmdd")、formatdate(now(),"现在是yy年第q季,一年中第ww个星期") 
 
三、时间的格式化显示 
 
system.datetime currenttime=new system.datetime();  
1.1 取当前年月日时分秒  
currenttime=system.datetime.now;  
1.2 取当前年  
int 年=currenttime.year;  
1.3 取当前月  
int 月=currenttime.month;  
1.4 取当前日  
int 日=currenttime.day;  
1.5 取当前时  
int 时=currenttime.hour;  
1.6 取当前分  
int 分=currenttime.minute;  
1.7 取当前秒  
int 秒=currenttime.second;  
1.8 取当前毫秒  
int 毫秒=currenttime.millisecond;  
(变量可用中文)  
 
1.9 取中文日期显示--年月日时分  
string stry=currenttime.tostring("f"); //不显示秒  
 
1.10 取中文日期显示_年月  
string strym=currenttime.tostring("y");  
 
1.11 取中文日期显示_月日  
string strmd=currenttime.tostring("m");  
 
1.12 取中文年月日  
string strymd=currenttime.tostring("d");  
 
1.13 取当前时分,格式为:14:24  
string strt=currenttime.tostring("t");  
 
1.14 取当前时间,格式为:2003-09-23t14:46:48  
string strt=currenttime.tostring("s");  
 
1.15 取当前时间,格式为:2003-09-23 14:48:30z  
string strt=currenttime.tostring("u");  
 
1.16 取当前时间,格式为:2003-09-23 14:48  
string strt=currenttime.tostring("g");  
 
1.17 取当前时间,格式为:tue, 23 sep 2003 14:52:40 gmt  
string strt=currenttime.tostring("r");  
 
1.18获得当前时间 n 天后的日期时间  
datetime newday = datetime.now.adddays(100);  
 
2、int32.parse(变量) int32.parse("常量")  
字符型转换 转为32位数字型  
 
3、 变量.tostring()  
字符型转换 转为字符串  
12345.tostring("n"); //生成 12,345.00  
12345.tostring("c"); //生成 ¥12,345.00  
12345.tostring("e"); //生成 1.234500e+004  
12345.tostring("f4"); //生成 12345.0000  
12345.tostring("x"); //生成 3039 (16进制)  
12345.tostring("p"); //生成 1,234,500.00% |