Asp. The processing of time in net

Source: Internet
Author: User
Tags datetime string format
The format for the ASP.net format method is:

public string Format (
string format,
Iserviceobjectprovider SP
);

Format refers to the formatting we specify, it has a lot of values, I have to list:

Standard format format formats
D mm/dd/yyyy (2001-3-27)
D dddd, MMMM DD, yyyy such as (March 27, 2001)
F dddd, MMMM dd, yyyy hh:mm (March 27, 2001 0:00)
F dddd, MMMM dd, yyyy HH:mm:ss (March 27, 2001 0:00:00)
G mm/dd/yyyy hh:mm (2001-3-27-0:00)
G mm/dd/yyyy HH:mm:ss (2001-3-27-0:00:00)
M, M MMMM DD (March 27)
R, R ddd, dd MMM yyyy HH ': ' mm ': ' ss ' GMT ' such as (Mon, Mar 2001 16:00:00 GMT)
S yyyy-mm-dd HH:mm:ss seems to be unable to use
T hh:mm as (0:00)
T HH:mm:ss as (0:00:00)
U yyyy-mm-dd HH:mm:ss (2001-03-26 16:00:00z)
U dddd, MMMM dd, yyyy HH:mm:ss (March 26, 2001 16:00:00)
Y, y MMMM, yyyy (March 2001)

Custom formatting list format pattern Description
D such as: 2001-3-27
DD such as: 27
DDD: Monday
dddd: Monday (full name)
M as: March 27
MM such as: 03
MMM such as: March
MMMM such as: March (full name)
Y: March 2001
yy such as: 01
yyyy such as: 2001
GG such as: A.D.
HH, hh* such as: 12
HH, hh* such as: 00
M as: March 27
MM, mm* such as: 00 (min)
S such as: 2001-03-27t00:00:00
SS, ss* such as: 00 (sec)
T such as: 0:00
TT, tt* such as: morning






The following is an example of a simple operation.

<% @ Page language= "C #"%>
<% @ Import namespace= "System.Data"%>
<script language= "C #" runat= "Server" >
public void Page_Load (Object Src,eventargs E)
{
DateTime dt = DateTime.Now;
CTime. Text=dt. Format ("MM", null). ToString ();
}
</script>
<title></title>
<body>
<asp:label id= "CTime" runat= "Server"/>
</body>


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.