To format a function that displays time in an ASP by a specified parameter

Source: Internet
Author: User
Tags format end string
function | display | function <%
' Function: Format the display time by the specified parameters.
' Numformat=1: Converts time to YYYY-MM-DD hh:nn format.
' numformat=2: Converts time to YYYY-MM-DD format.
' Numformat=3: Converts time to HH:NN format.
' Numformat=4: Converts the time to yyyy mm month DD Day hh when NN is divided into the format.
' Numformat=5: Converts time to yyyy mm month DD day format.
' numformat=6: NN split format when converting time to HH.
' Numformat=7: Converts the time to the yyyy year mm month DD Day x format.
' Numformat=8: Converts time to YYMMDD format.
' Numformat=9: Converts time to MMDD format.

function FormatDate (Shijian,numformat)
Dim ystr,mstr,dstr,hstr,nstr ' Variable meaning is year string, month string, day string, time string, string

If IsNull (Shijian) Then
Numformat=0
Else
Ystr=datepart ("yyyy", Shijian)

If DatePart ("M", Shijian) >9 Then
Mstr=datepart ("M", Shijian)
Else
Mstr= "0" &datepart ("M", Shijian)
End If

If DatePart ("D", Shijian) >9 Then
Dstr=datepart ("D", Shijian)
Else
Dstr= "0" &datepart ("D", Shijian)
End If

If DatePart ("H", Shijian) >9 Then
Hstr=datepart ("H", Shijian)
Else
Hstr= "0" &datepart ("H", Shijian)
End If

If DatePart ("n", Shijian) >9 Then
Nstr=datepart ("n", Shijian)
Else
Nstr= "0" &datepart ("n", Shijian)
End If
End If

Select Case Numformat
Case 0
Formatdate= ""
Case 1
formatdate=ystr& "-&mstr&"-"&dstr&" "&hstr&": "&nstr
Case 2
formatdate=ystr& "-" &mstr& "-" &dstr
Case 3
formatdate=hstr& ":" &nstr
Case 4
formatdate=ystr& "Year" &mstr& "month" &dstr& "Day" &hstr& "time" &nstr& "cent"
Case 5
formatdate=ystr& "Year" &mstr& "month" &dstr& "Day"
Case 6
formatdate=hstr& "Time" &nstr& "minutes"
Case 7
formatdate=ystr& "Year" &mstr& "month" &dstr& "Day" &weekdayname (Weekday (Shijian))
Case 8
Formatdate=right (ystr,2) &mstr&dstr
Case 9
Formatdate=mstr&dstr
End Select
End Function
%>

Now with asp.net everything is much simpler, or write to commemorate the original use of ASP's years.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.