<% ' 發展單位:風禹科技驗證有限公司 ' 撰寫人:鄭子璉(Tzu-Lien, Cheng, 璉璉) ,成大水利博肄,微軟最有價值專家 ' Web: http://tlcheng.twbbs.org/TLCheng/ E-Mail: qvb3377@ms5.hinet.net ' -------------------------------------------------------------------------------------- Public Function myFormatDate(ByVal vDate, ByVal strFormat) ' yyyy/mm/dd hh:nn:ss 分暫以 nn 取代 sDate = LCase(strFormat) ' rr, ee 民國 ' yyyy sDate = Replace(sDate, "yyyy", Year(vDate)) sDate = Replace(sDate, "yy", myFormatNumeric((Year(vDate) Mod 100), "00")) sDate = Replace(sDate, "ee", Year(vDate) - 1911) sDate = Replace(sDate, "rr", Year(vDate) - 1911) ' mm sDate = Replace(sDate, "mm", myFormatNumeric(Month(vDate), "00")) sDate = Replace(sDate, "m", Month(vDate)) ' dd sDate = Replace(sDate, "dd", myFormatNumeric(Day(vDate), "00")) sDate = Replace(sDate, "d", Day(vDate)) ' hh sDate = Replace(sDate, "hh", myFormatNumeric(Hour(vDate), "00")) sDate = Replace(sDate, "h", Hour(vDate)) ' nn sDate = Replace(sDate, "nn", myFormatNumeric(Minute(vDate), "00")) sDate = Replace(sDate, "n", Minute(vDate)) ' ss sDate = Replace(sDate, "ss", myFormatNumeric(Second(vDate), "00")) sDate = Replace(sDate, "s", Second(vDate)) myFormatDate = sDate End Function Public Function myFormatNumeric(ByVal vData, ByVal strFormat) If IsNull(vData) Then fmtNumeric = Null ElseIf strFormat = "" Then fmtNumeric = CStr(vData) Else sDot = Split(strFormat, ".") ' 偵測小數點 ubd = UBound(sDot) If ubd > 0 Then sNumeric = CStr(Round(vData, Len(sDot(1)))) If InStr(sNumeric, ".") = 0 Then sNumeric = sNumeric & "." End If Else sNumeric = CStr(Round(vData, 0)) End If sNumeric = Split(sNumeric, ".") ' 偵測小數點 sCommon = Split(sDot(0), ",") ' 偵測逗號 ubc = UBound(sCommon) If ubc > 0 Then nLen = Len(sNumeric(0)) nLoc = ((nLen - 1) Mod 3) + 1 For ic = 1 To (nLen - 1) \ 3 sNumeric(0) = Left(sNumeric(0), nLoc) & "," & Mid(sNumeric(0), nLoc + 1) nLoc = nLoc + 4 Next End If nLen = Len(sNumeric(0)) nDot = Len(sDot(0)) If nDot > nLen Then sAddFirst = Left(sDot(0), nDot - nLen) sAddFirst = Replace(sAddFirst, "#", "") sAddFirst = Replace(sAddFirst, ",", "") sNumeric(0) = sAddFirst & sNumeric(0) End If If ubd > 0 Then nLen = Len(sNumeric(1)) nDot = Len(sDot(1)) sNumeric(1) = sNumeric(1) & Mid(sDot(1), nLen + 1, nDot - nLen) sNumeric(1) = Replace(sNumeric(1), "#", "") End If fmtNumeric = Join(sNumeric, ".") End If myFormatNumeric = fmtNumeric End Function Public Function GetDataDateFormat(ByVal vDate, ByVal sFormat) sOutput = "" nStart = 1 Do sLoc = InStr(nStart, sFormat, "[") If sLoc > 0 Then eLoc = InStr(sLoc + 1, sFormat, "]") If eLoc > 0 Then midFormat = Mid(sFormat, sLoc + 1, eLoc - sLoc - 1) hLoc = InStr(LCase(midFormat), "&h") If hLoc > 0 Then fmt = Split(midFormat, ";") lbf = LBound(fmt) ubf = UBound(fmt) For ibf = lbf To ubf hLoc = InStr(LCase(fmt(ibf)), "&h") If hLoc > 0 Then fmtDate = fmtDate & Mid(fmt(ibf), 1, hLoc - 1) & Hex(CLng(myFormatDate(vDate, Mid(fmt(ibf), hLoc + 2)))) Else fmtDate = fmtDate & myFormatDate(vDate, fmt(ibf)) End If Next Else fmtDate = myFormatDate(vDate, midFormat) End If sOutput = sOutput & Mid(sFormat, nStart, sLoc - nStart) & fmtDate nStart = eLoc + 1 Else sOutput = sOutput & Mid(sFormat, nStart, sLoc - nStart) & "[" nStart = sLoc + 1 End If Else sOutput = sOutput & Mid(sFormat, nStart) End If Loop Until sLoc = 0 GetDataDateFormat = sOutput End Function %>