ASP format Date

Source: Internet
Author: User
Tags gmt time zone naming convention rfc string format

' PHP's date function format is implemented in ASP, and some non-ASP-capable format symbols are reserved for ' last UPDATE:2008/6/12 ' 1/Added GMT time zone definition ' 2/formattime with array for temporary return value ' 3/ Gformattime changed to Formatgtime, so that the function closer to the VBS format series of the naming convention ' 2008/8/7 ' add escape character support ' Greenwich GMT ' form the added [GMT] string in the function is removed, using the format string to define, reference example ' Added RFC 822 Protocol's date format ' 2009/3/8 ' formatgtime format date in type format, no longer uses the string format public Const Gmt_timezone = 8 ' with Greenwich time difference of hours, China is +8 public Function iif (ByVal blnexp, Vttrue, Vtfalse) If blnexp Then IIf = vttrue Else iif = Vtfalse End If End Function ' complement 0 Private function Fillzero (ByVal ivalue) Fillzero = IIf (Ivalue < 0, "") & Ivalue End Function function Formattime (byv Al Dtmvalue, ByVal strfmt) Dim Pweek Dim Pweekfull Dim Pmonth Dim Pmonthfull Dim ret, tmp Dim i, L Dim y, M, D, H, N, S, W Pweek = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat") Pweekfull = Array ("Sunday", "Monday", "Tuesday", "WEDNESDA") Y "," Thursday "," Friday "," Saturday ") Pmonth = Array (" The Same "," Feb "," Mar "," APR "," may "," June "," may "," Aug "," Sep "," Oct ", "Nov", "Dec") Pmonthfull = Array ("January", "FeBruary "," March "," April "," may "," June "," July "," August "," September "," October "," November "," December ") y = year (dtmva Lue) m = Month (dtmvalue) d = Day (dtmvalue) H = Hour (dtmvalue) n = Minute (dtmvalue) s = Second (dtmvalue) w = Weekday (dtmval UE) L = Len (strfmt) ReDim ret (l-1) for i = 1 to l TMP = Mid (strfmt, I, 1) Select Case tmp case "a": ' A lowercase morning and afternoon value am or PM RET (i-1) = IIf (H <, "AM", "PM") Case "a": ' An uppercase morning and afternoon value AM or PM ret (i-1) = IIf (H <, "AM", "PM") Case "B": ' B Swatch Internet standard 000 to 999 case "D": Day of the month of the "D", with a leading zero of 2 digits 01 to ret (i-1) = Fillzero (d) "D": the day of the D-week, text Indicates that the 3-letter Mon to Sun ret (i-1) = Pweek (w-1) case "F": ' F month, full text format, such as January or March January to December ret (i-1) = P Monthfull (m-1) Case "G": ' G-hour, 12-hour format, no leading 1 to ret (i-1) = (h Mod) case "G": ' G-hour, 24-hour format, no leading 00 to RET (i- 1 = h Case "h": ' H-hour, 12-hour format, with leading 1 to ret (i-1) = Fillzero (h Mod) case "H": ' H-hour, 24-hour format, with leading 000 to RET (i- 1) = Fillzero (h) Case "I":" I have a leading zero minutes of 00 to 59> ret (i-1) = Fillzero (n) Case "I": ' ret (i-1) = Tt->tm_isdst ' I is daylight saving time if it is daylight saving time or 0 case "J": ' Day of the month, no leading 1 to ret (i-1) = d case "L": ' l ' (lowercase letter of "L") days of the week, complete text format Sunday to Saturday ret (i-1) = Pweekfull (w 1) Case "L": ' l ' is a leap year if it is a leap year for 1, otherwise 0 ret (i-1) = IIf (y mod 4 = 0 and y mod <>0) or y mod = 0, 1, 0) "M": ' m digit month, with a leading 1 to ret (i-1) = Fillzero (m) case "M": ' m three-letter abbreviation for month to DEC ret (i-1) = Pmonth (m-1) case "N": ' N number of months, no leading 1 to ret (i-1) = M case "o": ' O ' hours apart from GMT for example: +0200 ret (i-1) = "$1$200" If Gmt_timezone < 0 Then ret (i-1) = replace (ret (i-1), "$", "-") Else ret (i-1) = replace (ret (i-1), "$", "+") End IF ret (i-1) = R Eplace (ret (i-1), "$", Fillzero (Abs (gmt_timezone)) case "R": ' r RFC 822 format date For example: Thu, Dec 16:01:07 +0200 ret (i -1 = formattime (Dtmvalue, "D, J M Y h:i:s O") case "s": ' s seconds, there is a leading 000 to 59> ret (i-1) = Fillzero (s) case "s": ' s per month day The English suffix after the number, 2 characters st,nd,rdor th. Can be used with J. Case "T": ' t the number of days for a given month 28 to If m = 1 or M = 3 or M = 5 or M = 7 or M = 8 or M = ten or M = Then ret (i-1) = If m = 4 or M = 6 Or m = 9 or M = one Then ret (i-1) = = (i-1) = IIf (y mod 4 = 0 and y mod <>0) Or y Mod = 0, "T": ' t ' time zone Case "U": ' The number of seconds since the start of the Unix era (January 1 1970 00:00:00 GMT) See Time () ret (i- 1 = DateDiff ("s", "1970-01-01 00:00:00", Dtmvalue) Case "W": ' W ' in the first days of the week, the number represents 0 (for Sunday) to 6 (for Saturday) ret (i-1) = W case "W": ' W ISO-8601 format year, weekly starting from Monday (PHP 4.1.0) For example: 42 (42nd Week of the year) case "Y": ' Y 4-digit year for full representation for example: 1999 or 2003 RET (i-1) = Y Cas E "y": ' Y 2-digit year for example: 99 or ret (i-1) = Right (y, 2) case "Z": ' Days of the year 0 to 366 ret (i-1) = DateDiff ("D", Y &) -01-01 ", dtmvalue) case" Z ": ' The number of seconds of the Z-slack offset. The time zone offset to the west of UTC is always negative, and the time zone offset to the east of UTC is always positive. Case "/": ' escape character i = i + 1 ret (i-1) = Mid (strfmt, I, 1) Case Else ret (i-1) = tmp end Select Next formattime = Join (ret, Empty) End Function ' inttype = format type, = 0, plus GMT suffix; = 1, plus UTC suffix public Function formatgtime (ByVal dtmvalue, ByVal inttype) formatgtime = Formattime (DateAdd ("H", 0-gmt_timezone, DTM Value), IIf (inttype = 0, "D, J M y h:i:s/g/m/t", "D, J M y h:i:s/u/t/c") end Function ' e.g. ' YYYY-MM-DD hh24:mi:ss format WSc Ript. Echo Formattime (now (), "y-m-d h:i:s") ' has a leading 0 date WScript.Echo Formattime (Now (), "Y-year m-month D-Day H (I minute s sec") ' no leading 0 date WScript.Echo Form Attime (now (), "Y year n months J Day g time I minute S") ' RFC 822 Protocol date format WScript.Echo Formattime (Now (), "R") ' GMT WScript.Echo Formatgtime (now ), 0 WScript.Echo Formatgtime (now (), 1)

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.