我想提取本机间的格为:2005-01-02 应该怎么提取啊,愁死啦!
date()
date()
公开我的转换函数,支持任意格式转换,与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编辑过]