| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1403 人关注过本帖
标题:提取时间格式问题,请大家帮忙
只看楼主 加入收藏
zzc
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-10-24
收藏
 问题点数:0 回复次数:16 
提取时间格式问题,请大家帮忙

我想提取本机间的格为:2005-01-02 应该怎么提取啊,愁死啦!

搜索更多相关主题的帖子: 格式 时间 
2005-11-17 16:05
jnzsk
Rank: 1
等 级:新手上路
威 望:1
帖 子:403
专家分:0
注 册:2004-11-13
收藏
得分:0 

date()


2005-11-17 16:10
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
VBScript中没有Format函数,而有FormatDateTime函数,但是FormatDateTime是将日期时间转换到本地时间格式,因此与计算机区域设置有关,最好的方法是自己编写一个函数来实现转换。

天津网站建设 http://www./
2005-11-17 16:15
zzc
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-10-24
收藏
得分:0 
我用DATE()可是提格为:2005-1-1,我想提取为2005-01-01,该怎么办啊,谢谢
2005-11-17 16:21
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5810
专家分:118
注 册:2005-4-7
收藏
得分:0 
<%=year(now())%>-<%=month(now())%>-<%=day(now())%>

2005-11-17 16:22
zzc
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-10-24
收藏
得分:0 

谢谢大家!

可还是不行啊,还是2005-1-1啊!

2005-11-17 16:28
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 

公开我的转换函数,支持任意格式转换,与VB中Format函数功能相当,并扩展了转换为英文、12小时制等功能

'*********************************************************
' Purpose: Convert Local Date/Time Format String to Special Format.
'  example:Convert 5/1/2005 To 2005-05-01 By FormatDate("5/1/2005","yyyy-mm-dd")
' Inputs: varDate: the The Local Date/Time to be Convert.
' Format: the Special Format String.
' the following string before "->" will be convert
' to the Special string after.
' yyyy->Long Year mm->Long Month dd->Long Day
' yy->Short Year m->Short Month d->Short Day
' hh->Long Hour nn->Long Minute ss->Long Second
' h->Short Hour n->Short Minute s->Short Second
' WW->Week day
' TT->English month
' TAU->AM/PM TAL->am/pm
' Returns: Special Format of Some Date/Time String
'
'Author: griefforyou / griefforyou(at)163.com
'*********************************************************
Function FormatDate(varDate, sFormat)
Dim sYear, sShortyear
Dim sMonth, sShortmonth
Dim sDay, sShortday
Dim sHour, sMinute, sSecond
Dim sShorthour, sShortminute, sShortsecond
Dim hour12
Dim tal, tau
Dim temp

If Not IsDate(varDate) Then
FormatDate = varDate
Exit Function
End If
If sFormat = "" Then sFormat = "MM/dd/yy"

sYear = DatePart("yyyy", varDate)
sShortyear = Right(sYear, 2)
sShortmonth = DatePart("M", varDate)
If Len(sShortmonth) = 2 Then
sMonth = sShortmonth
Else
sMonth = "0" & sShortmonth
End If

sShortday = DatePart("d", varDate)
If Len(sShortday) = 2 Then
sDay = sShortday
Else
sDay = "0" & sShortday
End If

sShorthour = DatePart("h", varDate)
If Len(sShorthour) = 2 Then
sHour = sShorthour
Else
sHour = "0" & sShorthour
End If

If sShorthour >= 0 And sShorthour < 12 Then
tal = "am"
tau = "AM"
Else
tal = "pm"
tau = "PM"
End If

If sShorthour = 0 Or sShorthour = 12 Then
hour12 = "12"
Else
hour12 = CStr(sShorthour Mod 12)
End If

if Len(hour12) = 1 Then
hour12 = "0" & hour12
End If

sShortminute = DatePart("n", varDate)
If Len(sShortminute) = 2 Then
sMinute = sShortminute
Else
sMinute = "0" & sShortminute
End If

sShortsecond = DatePart("s", varDate)
If Len(sShortsecond) = 2 Then
sSecond = sShortsecond
Else
sSecond = "0" & sShortsecond
End If

temp = Replace(sFormat, "yyyy", sYear)
temp = Replace(temp, "yy", sShortyear)
temp = Replace(temp, "mm", sMonth)
temp = Replace(temp, "m", sShortmonth)
temp = Replace(temp, "dd", sDay)
temp = Replace(temp, "d", sShortday)
temp = Replace(temp, "hh12", hour12)
temp = Replace(temp, "hh", sHour)
temp = Replace(temp, "nn", sMinute)
temp = Replace(temp, "ss", sSecond)
'temp = Replace(temp, "h12", shorthour)
temp = Replace(temp, "h", sShorthour)
temp = Replace(temp, "n", sShortminute)
temp = Replace(temp, "s", sShortsecond)
temp = Replace(temp, "TT", TransMonthToEnglish(varDate))
temp = Replace(temp, "TAL", tal)
temp = Replace(temp, "TAU", tau)
temp = Replace(temp, "WW", TransWeekDayToEnglishByIndex((DatePart("w", varDate) + 5) Mod 7))
FormatDate = temp
End Function

Function TransMonthToEnglish(dateMonth)
Const strMonth=",Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
Dim ArrMonth
ArrMonth=Split(strMonth,",")
TransMonthToEnglish=ArrMonth(DatePart("m",dateMonth))
End Function

Function TransWeekDayToEnglishByIndex(DayIndex)
Const strWeekDay="Mon,Tues,Wed,Thurs,Fri,Sat,Sun"
Dim ArrWeekDay
ArrWeekDay=Split(strWeekDay,",")
TransWeekDayToEnglishByIndex=ArrWeekDay(DayIndex)
End Function

[此贴子已经被作者于2005-11-17 16:31:29编辑过]


天津网站建设 http://www./
2005-11-17 16:28
zzc
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-10-24
收藏
得分:0 
辛苦了,谢谢griefforyou
2005-11-17 16:39
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
举例:

2005-1-1 20:02:23 转为 2005-01-01
FormatDate("2005-1-1 20:02:23 ","yyyy-mm-dd")

2005-1-1 20:02:23 转为 Jan 01, 2005, 08:02:23 PM
FormatDate("2005-1-1 20:02:23 ","TT dd, yyyy, hh12:nn:ss TAU")


天津网站建设 http://www./
2005-11-17 16:40
zzc
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-10-24
收藏
得分:0 
太感谢了,我明白了。
2005-11-17 16:45
快速回复:提取时间格式问题,请大家帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022704 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved