65.9K
CodeProject 正在变化。 阅读更多。
Home

显示服务器的当前日期

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.29/5 (4投票s)

2000年2月15日

CPOL
viewsIcon

90931

一个简单的例程,用于在客户端浏览器中显示服务器的当前日期。

这里有一个简单的函数,用于在服务器上显示日期,根据 Abbreviate 是否为 True 或 False,以 '7 Feb 2002' 或 'Thursday 7th February, 2002' 的形式显示。

' DateVal is the date to display

' If Abbreviate is True then the date is displayed in short form

' Otherwise it's displayed verbose

Function DateString(DateVal, Abbreviate)
Dim intDate, strDay, strMonth, strYear

    intDate  = Day(DateVal)
    strYear  = Year(DateVal)
    
    if Abbreviate Then
        strMonth = MonthName(Month(DateVal), True)
        DateString = intDate & " " & MonthName(Month(DateVal), True) & " " & strYear
    Else
        strMonth = MonthName(Month(DateVal))
        strDay   = WeekDayName(WeekDay(DateVal), False, vbSunday)

        Dim suffix
        suffix   = "th"
        Select Case intDate
            case 1,21,31 : suffix = "st"
            case 2,22    : suffix = "nd"
            case 3,23    : suffix = "rd"
        End Select

        DateString  = strDay & " " & intDate & suffix & " " & strMonth & ", " & strYear
    End If
End Function

要在 ASP 页面中使用它,只需包含上面的脚本,然后在希望显示日期的地方添加以下内容

<p>Today is <%= DateString(Date(), False) %></p>
© . All rights reserved.