我现在有点傻了……

我有一个欧洲格式的日期字符串 年月日 并需要将其转换为 年月日 与经典的 ASP。有什么快速的想法吗?

有帮助吗?

解决方案

如果它始终采用这种格式,您可以使用 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

我有自己的日期操作函数,在所有应用程序中都使用它,但它最初基于此示例:

http://www.adopenstatic.com/resources/code/formatdate.asp

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top