| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 456 人关注过本帖
标题:求教:关于时间日期格式设置问题
收藏  订阅  推荐  打印 
哈马拟
Rank: 3Rank: 3
等级:中级会员
帖子:270
积分:2800
注册:2004-7-15
求教:关于时间日期格式设置问题

我想把日期的格式设置成这样的形式:“02/29/04”

该用哪条语句呢?

搜索更多相关主题的帖子: 格式  时间  语句  
2004-9-5 08:03
griefforyou
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:27
帖子:3338
积分:33882
注册:2004-4-15

在VBScript里没有现成的函数

四月天原创文学网 http://yc.4yt.net
2004-9-5 13:39
griefforyou
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:27
帖子:3338
积分:33882
注册:2004-4-15

我帮你写了个函数来格式化日期

<% '//////////////////////////////////////////////////////////////////////////// '格式化时间字符串函数,Written by griefforyou '参数:varDate为时间字符串 '参数:Format参数为格式字符串,格式字符串中可以包含yyyy(四位数年份),yy(两位数年份) 'MM(长格式月份),M(短格式月份),dd(长格式日期),d(短格式日期) '//////////////////////////////////////////////////////////////////////////// Private Function FormatDate(varDate ,Format) Dim year ,shortyear Dim month , shortmonth Dim day , shortday Dim temp

If Not IsDate(varDate) Then Exit Function If Format="" then Format= "MM/dd/yy"

year = DatePart("yyyy", varDate) shortyear = Right(year, 2) shortmonth = DatePart("M", varDate) If Len(shortmonth) = 2 Then month = shortmonth Else month = "0" & shortmonth End If shortday = DatePart("d", varDate) If Len(shortday) = 2 Then day = shortday Else day = "0" & shortday End If temp = Replace(Format, "yyyy", year) temp = Replace(temp, "yy", shortyear) temp = Replace(temp, "MM", month) temp = Replace(temp, "M", shortmonth) temp = Replace(temp, "dd", day) temp = Replace(temp, "d", shortday) FormatDate = temp End Function

%> 函数使用示例:<br> Now 当前日期为 <%=Now%><br> FormatDate(Now,"") 返回值为 "<%=FormatDate(Now,"")%>" (默认Format参数为"MM/dd/yy")<br> FormatDate(Now,"MM/dd/yy") 返回值为 "<%=FormatDate(Now,"MM/dd/yy")%>" <br> FormatDate(Now,"M/d/yy") 返回值为 "<%=FormatDate(Now,"M/d/yy")%>" <br> FormatDate(Now,"yyyy-MM-dd") 返回值为 "<%=FormatDate(Now,"yyyy-MM-dd")%>"<br> FormatDate(Now,"MM/dd/yyyy") 返回值为 "<%=FormatDate(Now,"MM/dd/yyyy")%>"<br> FormatDate(Now,"yyyy/M/d") 返回值为 "<%=FormatDate(Now,"yyyy/M/d")%>"<br> FormatDate(Now,"yyyy-M-d") 返回值为 "<%=FormatDate(Now,"yyyy-M-d")%>"<br>

输出结果如下:

[此贴子已经被作者于2004-09-05 14:18:04编辑过]

附件: 只有本站会员才能下载或查看附件,请您 登录注册

四月天原创文学网 http://yc.4yt.net
2004-9-5 14:14
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.094230 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved