In ASP.NET, M $ provides us with a target called DateTime, we use this object to get the current time. such as:
DateTime DT = datetime.now;
In the above program we have obtained a 24-way time object called DT, if we have to get 12-system time object, you can use another statement
DateTime DT = DateTime.toDay;
But whether it is NOW or Today, our time we have achieved is just a shape such as 2001-03-27T00: 57: 09. It may be in general, this time is enough (for example, we just get the current time), but in actual life, we need not only this big series, we need to get specific seconds, minutes, always Wait, then this big string number is not all we need, and in the ASP's Time function provides us with these objects such as Second, Minute, Hour, but in ASP.NET, this is not. I have seen some friends in order to obtain a specific minute, and write a function separately from the desired time in the string obtained by DateTime.now. This is also a way to do this when we don't know the use of DateTime.
Fortunately, M $ provides our Format method, using our ability to get our time format we want.
The format of the Format method is:
Public String Format
String Format,
IServiceObjectProvider SP
);
Format refers to the format we specified, there are a lot of values, I have to list :)
Standard Format Format Format Format Mode
D mm / dd / yyyy (2001-3-27)
D DDDD, MMMM DD, YYYY (March 27, 2001)
f DDDD, MMMM DD, YYYY HH: MM, such as (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 such as (2001-3-27 0:00:00)
M, M mmmm DD, such as (March 27)
R, R DDD, DD MMM YYYY HH ':' mm ':' s 'GMT', such as (Mon, 26 Mar 2001 16:00:00 GMT)
s YYYY-MM-DD HH: MM: SS does not seem to use
T hh: mm such as (0:00)
T hh: mm: ss such as (0:00:00)
U YYYY-MM-DD HH: mm: SS such as (2001-03-26 16: 00:00Z)
U DDDD, MMMM DD, YYYY HH: mm: SS, (March 26, 2001 16:00)
Y, y mmmm, yyyy (March 2001)
Custom Format List Format Pattern Description
D as: 2001-3-27
DD as: 27
DDD such as: Monday
DDDD, as: Monday (full name)
M as: March 27
MM, 03
MMM such as: March
MMMM such as: March (full name)
Y is as: March 2001
YY, 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 (minutes)
S such as: 2001-03-27T00: 00: 00
SS, SS * such as: 00 (seconds) T is as: 0: 00
TT, TT * such as: morning
Here is an example of a simple operation.
<% @ Page language = "c #"%>
<% @ Import namespace = "system.data"%>
Public void Page_Load (Object SRC, Eventargs E)
{
DateTime DT = datetime.now;
CTIME.TEXT = DT.Format ("mm", null) .tostring ();
}
script>
hEAD>
body>
html>