在ASP(VB)中自定义日期格式的函数
2006-12-31 11:39
369 查看
代码如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Function AddZero(val, digit)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dim Ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Ret = CStr(val)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Ret = Replace(Space(digit - Len(val)), " ", "0") & Ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AddZero = ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Function FormatDataTime(dt, format)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dim ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(format, "MM", AddZero(Month(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "M", Month(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "mm", AddZero(Minute(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "m", Minute(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = UCase(ret)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "YYYY", Year(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "DD", Day(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "D", AddZero(Day(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "HH", Hour(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "H", AddZero(Hour(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "SS", AddZero(Second(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "S", Second(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
FormatDataTime = ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Response.Write FormatDataTime(Now, "yyyy-MM-dd hh:mm:ss")
显示结果:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
2006-12-31 11:37:27
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Function AddZero(val, digit)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dim Ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Ret = CStr(val)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Ret = Replace(Space(digit - Len(val)), " ", "0") & Ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
AddZero = ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Function FormatDataTime(dt, format)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Dim ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(format, "MM", AddZero(Month(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "M", Month(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "mm", AddZero(Minute(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "m", Minute(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = UCase(ret)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "YYYY", Year(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "DD", Day(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "D", AddZero(Day(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "HH", Hour(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "H", AddZero(Hour(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "SS", AddZero(Second(dt), 2))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ret = Replace(ret, "S", Second(dt))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
FormatDataTime = ret
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Response.Write FormatDataTime(Now, "yyyy-MM-dd hh:mm:ss")
显示结果:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
2006-12-31 11:37:27
相关文章推荐
- ASP.Net Core 返回的json数据,自定义日期格式
- Oracle个别日期格式在SQL Server中的转换(自定义函数)
- asp.net 获取日期格式的各种函数
- ASP.NET日期格式函数
- 详细介绍asp.net获取日期时间的各种格式的函数
- 主攻ASP.NET.3.5.MVC3.0架构之重生:自定义农历日期天气格式Helper
- 用getdate()函数自定义日期格式
- getdate()函数自定义日期格式
- vb 表达式大全,函数,用DateTime.ToString(string format)输出不同格式的日期
- Asp.NET常用函数 (VB.net) [转]
- NSDateFormatter setDateFormat 自定义日期/时间格式
- MyEclipse 中自定义日期格式
- ASP.NET日期处理函数
- ASP.NET(C#)中使数据库中读取的文本换原格式显示的函数
- asp自定义函数可以返回数组或者对象
- Asp.Net日期时间格式设置
- JavaScript格式化日期时间的方法和自定义格式化函数示例
- 让 VB 执行自定义字符串代码的 API 函数。
- jQuery asp.net 用json格式返回自定义对象
- Asp.net中的日期处理函数