我现在有点傻……</p>
我有一个欧洲格式 dd.mm.yyyy 的日期字符串,需要使用经典 ASP将其转换为mm.dd.yyyy 。有什么快速的想法吗?
如果它总是采用那种格式,你可以使用 split
d = split(".","dd.mm.yyyy")
s = d(1) & "." & d(0) & "." & d(2)
这也允许像 1.2.99 这样的日期
Dim arrParts() As String
Dim theDate As Date
arrParts = Split(strOldFormat, ".")
theDate = DateTime.DateSerial(parts(2), parts(1), parts(0))
strNewFormat = Format(theDate, "mm.dd.yyyy")
好的,我自己找到了一个解决方案:
payment_date = MID(payment_date,4,3) & LEFT(payment_date,3) & MID(payment_date,7)
这是一种通过内置的日期健全性检查来做到这一点的方法:
Dim OldString, NewString
OldString = "31.12.2008"
Dim myRegExp
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((19|20)[0-9]{2})"
If myRegExp.Test Then
NewString = myRegExp.Replace(OldString, "$2.$1.$3")
Else
' A date of for instance 32 December would end up here
NewString = "Invalid date"
End If
我有自己的日期操作函数,我在所有应用程序中都使用它,但它最初是基于这个示例:
function MyDateFormat(mydate)
'format: YYYYMMDDHHMMSS
MyDateFormat = year(mydate) & right("0" & month(mydate),2) & _
right("0" & day(mydate),2) & right("0" & hour(mydate),2) &_
right("0" & minute(mydate),2) & right("0" & second(mydate),2)
end function
response.write(MyDateFormat(Now))
显示:20200623102805