ASP 经典 IsDate 返回错误结果

问题描述 投票:0回答:2

我的 IIS 配置可能有问题。 Windows Server 2012 基金会 信息系统 8 本地系统捷克语,日期格式 dd.mm.rr ASP经典

IsDAte("18-10-13") - TRUE
IsDAte("18#10#13") - TRUE
IsDAte("18.10.13") - FALSE
IsDAte("18.10.2013") - TRUE

我需要 IsDAte(18.10.13) 返回 true。 为什么现在 IsDAte(18.10.13) 返回 false?

iis asp-classic
2个回答
2
投票

更新:

isDate
检查似乎返回无关紧要的结果与 2 位数的年份输入,所以你可以使用这个函数来检查有效日期:

function checkDate(datestr)
    dim temp, dt, d, m, y
    
    checkDate = false
    temp = split(datestr, ".")
    if UBound(temp) = 2 then
        d = CInt(temp(0))
        m = CInt(temp(1))
        y = CInt(temp(2))
        if y<100 then
            y = 2000 + y
        end if

        dt = DateSerial(y, m, d)
        if day(dt)=d and month(dt)=m then
            checkDate = true
        end if
    end if
end function

DateSerial 函数调用和日期和月份的检查被插入以确保无效日期,例如 30.02.2013 将返回 false。它还支持 4 位数字的年份输入,但您应该知道,您将在几百年后使用此功能遇到 Y3k 问题。 :)


正如@Elie 所说, isDate 使用当前的区域设置。但是你可以设置你想要匹配所需日期格式的语言环境。

dim locale
' uses your current locale and will return false
Response.Write "<p>TEST: " & isDate("15.10.2013") & " --> " & GetLocale() & "</p>"

locale = GetLocale() ' save current locale
SetLocale(1031) ' de_AT

' uses de_AT locale and will return true
Response.Write "<p>TEST: " & isDate("15.10.2013") & " --> " & GetLocale() & "</p>"

SetLocale(locale) ' restore your locale

查找语言环境ID列表以找到正确的数字


0
投票

IsDate 函数使用本地设置来确定字符串是否可以转换为日期。 更多信息这里.

我认为 Windows Server 2012 上的日期设置不提供“DD.MM.YY”选项。

© www.soinside.com 2019 - 2024. All rights reserved.