About time processing in ASP.NET

xiaoxiao2021-03-06  73

In ASP.NET, M $ provides us with a target called DateTime, we use this object to get the current time. For example: 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 list :) Standard Format format Format Format mode D mm / dd / yyyy Such as (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, such as (March 27, 2001) g mm / dd / yyyyh: mm such as (2001-3-27 0:00) g mm / dd / yyyyh: 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 use T HH: mm, (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:) U DDDD, MMMM DD, YYYY HH: mm: SS, (March 26, 2001 16:00:00) Y , Y, YYYY, such as (March 2001) Custom format list Format Pattern Description D as: 2001-3-27 DD, as: 27 DDD, Monday DDDD, Monday (full name) M, March 27 mm, like: 03 mmm, such as: March mmmm, March (full name) Y, March 2001, YYY, such as: 01 YYYY : 2001 GG such as: ad hh, hh * such as: 12 hh, hh * such as: 00 M: March 27 mm, mm * such as: 00 (minutes) S, 2001-03-27T00: 00: 00 SS, SS * such as: 00 (second) T is as: 0: 00 tt, tt * such as: The morning is an example of a simple operation.

转载请注明原文地址:https://www.9cbs.com/read-121112.html

New Post(0)