ASP Common date Format Function FormatDate () _ Application techniques

Source: Internet
Author: User
Tags rfc822

Core code

<% ' function: Multifunction date Format function ' Source: http://jorkin.reallydo.com/article.asp?id=477 function FormatDate (sdatetime, Sreallydo) Dim  Sjorkin Sjorkin = GetLocale () If not IsDate (sdatetime) Then sdatetime = Now () Sdatetime = CDate (sdatetime) Select case
  UCase (Sreallydo & "") case "0", "1", "2", "3", "4" formatdate = FormatDateTime (sdatetime, Sreallydo) case "00"
 FormatDate = FormatDate (Sdatetime, "Yyyy-mm-dd hh:mm:ss") case "a" formatdate = FormatDate (Sdatetime, "YYYY year MM month DD Day")
 Case "a" formatdate = FormatDate (Sdatetime, "YYYY-MM-DD") case "" FormatDate = FormatDate (Sdatetime, "Hh:mm:ss") Case "a" formatdate = FormatDate (Sdatetime, "hh:mm") case "ISO8601", "GOOGLE", "SITEMAP" '//iso8601 format, generally used for Googlesitem
  AP, "+08:00" is the time zone. FormatDate = FormatDate (Sdatetime, "yyyy-mm-ddthh:mm:ss.000+08:00") case "RFC822", "RSS", "feed" '//rfc822 format, generally used for RSS, "
  +0800 "is the time zone. SetLocale ("EN-GB") FormatDate = FormatDate (Sdatetime, "Ew, DD eMM YYYY hh:mm:ss +0800") SetLocale (Sjorkin) CasE "RND", "RAND", "RANDOMIZE" '//random string RANDOMIZE Sjorkin = RND () formatdate = FormatDate (Sdatetime, "YYYYMMDDHHMMSS") & _ Fix ((9 * 10^6-1) * Sjorkin) + 10^6 case Else formatdate = Sreallydo formatdate = Replace (FormatDate, "Y YYY ", Year (sdatetime)) FormatDate = replace (formatdate," DD ", Right (" 0 "& Day (Sdatetime), 2)) FormatDate = Replace
  (FormatDate, "HH", Right ("0" & Hour (Sdatetime), 2) FormatDate = replace (formatdate, "MM", right ("0" & Minute (Sdatetime), 2)) FormatDate = replace (formatdate, "SS", Rig HT ("0" & Second (Sdatetime), 2)) FormatDate = Replace (formatdate, "YY", Right (year (Sdatetime), 2)) FormatDate = Rep Lace (formatdate, "D", Day (sdatetime)) FormatDate = replace (formatdate, "H", Hour (sdatetime)) FormatDate = replace (Form  Atdate, "M", Minute (sdatetime)) FormatDate = Replace (formatdate, "s", Second (sdatetime)) If InStr (1, FormatDate, "EW", 1) > 0 Then SetLocale ("EN-GB") FormatDate = Replace (formatdate, "EW", UCase (WeekDayname (Weekday (sdatetime), false)) FormatDate = Replace (formatdate, "EW", WeekdayName (Weekday (sdatetime), false)) Fo Rmatdate = replace (formatdate, "Ew", UCase (WeekdayName (Weekday (sdatetime), True)) FormatDate = replace (formatdate, "EW" ", WeekdayName (Weekday (sdatetime), True) SetLocale (sjorkin) Else formatdate = Replace (formatdate," W ", WeekdayName ( Weekday (Sdatetime), False)) FormatDate = Replace (FormatDate, "W", WeekdayName (Weekday (sdatetime), True)) End If I NSTR (1, FormatDate, "Emm", 1) > 0 Then SetLocale ("EN-GB") FormatDate = Replace (formatdate, "Emm", MonthName (Month (s DateTime), False) formatdate = Replace (formatdate, "EMM", MonthName (Month (sdatetime), True) SetLocale (Sjorkin) Els E formatdate = replace (formatdate, "MM", Right ("0" & Month (Sdatetime), 2)) FormatDate = replace (FormatDate, "M", M

 Onth (Sdatetime)) End-If end Select-end Function%>

Usage is as follows:

<%
' Formats the date into ISO8601 format
Response.Write (FormatDate ("2008-03-06 08:03:06", "SITEMAP"))
' Format dates into RFC822 format
Response.Write (FormatDate ("2008-03-06 08:03:06", "RSS"))
' Format the date (English, British, or Japanese/year)
Response.Write (Now (), "EW, emm/dd/yyyy"))
' will generate a string Response.Write with a random number of minutes from the date of the Year (now) (The
formatdate (now ), "RND")
%>

More can view the following related articles

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.