ASP format date

Source: Internet
Author: User
1 I 've posted some of the articles I 've used to write code recently. I 'd like to thank those elders for some good methods.
2
3 < %
4 ' ========================================================== ====
5 ' Formatting time (Display)
6 ' Parameter: n_flag
7 ' 1: "yyyy-mm-dd hh: mm: SS"
8 ' 2: "yyyy-mm-dd"
9 ' 3: "HH: mm: SS"
10 ' 4: "mm DD, YYYY"
11 ' 5: "yyyymmdd"
12 ' 6: "yyyymmddhhmmss"
13 ' ========================================================== ====
14 Function Format_time (s_time, n_flag)
15 Dim Y, M, D, H, mi, S
16 Format_time =   ""  
17 If   Isdate (S_time) =   False   Then   Exit   Function  
18 Y =   CSTR ( Year (S_time ))
19 M =   CSTR ( Month (S_time ))
20 If   Len (M) =   1   Then M =   " 0 "   & M
21 D =   CSTR ( Day (S_time ))
22 If   Len (D) =   1   Then D =   " 0 "   & D
23 H =   CSTR ( Hour (S_time ))
24 If   Len (H) =   1   Then H =   " 0 "   & H
25 Mi =   CSTR ( Minute (S_time ))
26 If   Len (MI) =   1   Then Mi =   " 0 "   & Mi
27 S =   CSTR ( Second (S_time ))
28 If   Len (S) =   1   Then S =   " 0 "   & S
29 Select   Case N_flag
30 Case   1  
31 ' Yyyy-mm-dd hh: mm: SS
32 Format_time = Y &   " - "   & M &   " - "   & D &   "   "   & H &   " : "   & Mi &   " : "   & S
33 Case   2  
34 ' Yyyy-mm-dd
35 Format_time = Y &   " - "   & M &   " - "   & D
36 Case   3  
37 ' Hh: mm: SS
38 Format_time = H &   " : "   & Mi &   " : "   & S
39 Case   4  
40 ' Yyyy-mm-dd
41 Format_time = Y &   " Year "   & M &   " Month "   & D &   " Day "  
42 Case   5  
43 ' Yyyymmdd
44 Format_time = Y & M & D
45 Case   6  
46 ' Yyyymmddhhmmss
47 Format_time = Y & M & D & H & Mi & S
48 End   Select  
49 End Function  
50 % >
51
52 < % = Format_time ( Now , 1 ) % >
53

You can use the formatdatetime function to convert a long date format to a short date format.

Formatdatetime Function
See
Formatcurrency function | formatnumber function | formatpercent Function
Requirements
Version 2
Return expression, which has been formatted as a date or time.

Formatdatetime (date [, namedformat])
Parameters
Date
Required. The date expression to be formatted.
Namedformat
Optional. Indicates the value of the date/time format used. If it is omitted, vbgeneraldate is used.
Set
The namedformat parameter can have the following values:

Constant Value description
Vbgeneraldate 0 displays the date and/or time. If there is a date part, it is displayed as the short date format. If there is a time part, it is displayed as a long time format. If all exist, all parts are displayed.
Vblongdate 1 displays the date in the long date format specified in the computer region settings.
Vb1_date 2 displays the date in the short date format specified in the computer region settings.
Vblongtime 3 displays the time in the specified time format in the computer region settings.
Vb1_time 4 uses the 24-hour format (HH: mm) to display the time.

Description
The following example uses the formatdatetime function to format the expression as a long date type and assign it to mydatetime:

Function getcurrentdate
'Formatdatetime format the date type to the long date type.
Getcurrentdate = formatdatetime (date, 1)
End Function
Requirements
Version 2

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.