NET get system Current time (reprint)

Source: Internet
Author: User
Tags locale setting month name

NET get system Current time(2011-06-17 13:26:10) reproduced
Tags: it Category: My actual combat
24-hour System: DateTime dt = DateTime.Now; String dt24 = dt. ToString ("Yyyy-mm-dd HH:mm:ss"); 12-hour System: DateTime dt = DateTime.Now; String dt12 = dt. ToString ("Yyyy-mm-dd hh:mm:ss"); The case of H determines
If you want to get the full system time, just like you say the format, actually directly write: System.DateTime.Now.ToString (); it's the default format 24 hours, and that's what you want,
In C #/ASP, we can get the current time by using the Datatime class. We can get different times by invoking various methods in the class: Date (2008-09-04), Time (12:12:12), date + time (2008-09-04 12:11:10), etc.
Get Date + Time
DateTime.Now.ToString (); 2008-9-4 20:02:10
DateTime.Now.ToLocalTime (). ToString (); 2008-9-4 20:12:12
Get Date
DateTime.Now.ToLongDateString (). ToString (); September 4, 2008
DateTime.Now.ToShortDateString (). ToString (); 2008-9-4
DateTime.Now.ToString ("Yyyy-mm-dd"); 2008-09-04
DateTime.Now.Date.ToString (); 2008-9-4 0:00:00
Get time
DateTime.Now.ToLongTimeString (). ToString (); 20:16:16
DateTime.Now.ToShortTimeString (). ToString (); 20:16
DateTime.Now.ToString ("Hh:mm:ss"); 08:05:57
DateTime.Now.TimeOfDay.ToString (); 20:33:50.7187500
Other
Datetime.tofiletime (). ToString (); 128650040212500000
DATETIME.NOW.TOFILETIMEUTC (). ToString (); 128650040772968750
DateTime.Now.ToOADate (). ToString (); 39695.8461709606
DateTime.Now.ToUniversalTime (). ToString (); 2008-9-4 12:19:14
DateTime.Now.Year.ToString (); Get year//2008
DateTime.Now.Month.ToString (); Get Month//9
DateTime.Now.DayOfWeek.ToString (); Get Week//Thursday
DateTime.Now.DayOfYear.ToString (); Get the day of the Week//248
DateTime.Now.Hour.ToString (); Get hours//20
DateTime.Now.Minute.ToString (); Get minutes//31
DateTime.Now.Second.ToString (); Gets the number of seconds//45
N is a number, can be a number of integers, can also matter a decimal
Dt. AddYears (n). ToString (); Time Plus n years
Dt. AddDays (n). ToString (); Plus n days
Dt. AddHours (n). ToString (); Add N Hours
Dt. AddMonths (n). ToString (); Add n months
Dt. AddSeconds (n). ToString (); Plus n seconds
Dt. AddMinutes (n). ToString (); Add n Points
1.string strtime = DateTime.Now.ToLongTimeString ();
2.
DateTime dt = DateTime.Now;
String str = dt. ToString ("Yyyy-mm-dd");
Or
String str = DateTime.Now.ToString ("Yyyy-mm-dd");
Or
String str = DateTime.Now.ToShortDateString ();
3.datetime.now.tostring ("Yyyy-mm-dd"); Take the date, get the format as 2005-02-18
DateTime.Now.ToString ("Hh:mm:ss"); take time to get a format like 10:45:30
Format display
M/d/yy 12/7/58
D-mmm 7-dec
D-mmmm-yy 7-december-58
D MMMM 7 December
MMMM yy December 58
hh:mm TT 08:50 PM
H:mm:ss T 8:50:35 P
h:mm 20:50
H:mm:ss 20:50:35
m/d/yyyy h:mm 12/7/1958 20:50
Character description
(:) The time separator character. In some locales, you can use other characters to represent time separators. The time separator separates hours, minutes, and seconds when formatting time values. The actual character used as the time separator in the formatted output is determined by the system's LocaleID value.
(/) Date separator. In some locales, you can use other characters to represent the date separator. The date separator separates day, month, and year when formatting date values. The actual character used as the date separator in the formatted output is determined by your locale setting.
(%) Used to indicate that no matter what letter is trailing, subsequent characters should be read in single-letter format. Also used to indicate that a single-letter format should be read in a user-defined format. For more information, see the section below.
D Displays the day as a number without leading zeros (such as 1). If this is the only character in the user-defined number format, use%d.
DD Displays the day as a number with leading zeros (such as 01).
DDD Displays the day as an abbreviated form (for example, Sun).
DDDD Displays the day as the full name (for example, Sunday).
M Displays the month as a number without leading zeros (for example, January is represented as 1). If this is the only character in a user-defined number format, use%M.
MM Displays the month as a number with leading zeros (for example, 01/12/01).
MMM Displays the month as an abbreviated form (for example, Jan).
MMMM Displays the month as a full month name (for example, January).
GG Displays the era/era string (for example, A.D.)
H displays the hour as a number without leading zeros (for example, 1:15:15 PM) using a 12-hour system. If this is the only character in a user-defined number format, use%h.
HH uses a 12-hour system to display the hour as a number with leading zeros (for example, 01:15:15 PM).
H displays the hour as a number without leading zeros using a 24-hour system (for example, 1:15:15). If this is the only character in a user-defined number format, use%H.
HH uses a 24-hour system to display the hour as a number with leading zeros (for example, 01:15:15).
M displays the minute as a number without leading zeros (for example, 12:1:15). If this is the only character in a user-defined number format, use%m.
MM Displays the minute as a number with leading zeros (for example, 12:01:15).
s displays the seconds as a number without leading zeros (for example, 12:15:5). If this is the only character in a user-defined number format, use%s.
The SS displays seconds as a number with leading zeros (for example, 12:15:05).
F shows the decimal part of the second. For example, the FF will be accurately displayed to 1% seconds, and the FFFF will be displayed exactly one out of 10,000 seconds. You can use up to seven F symbols in a user-defined format. If this is the only character in a user-defined number format, use%f.
T uses a 12-hour system, and displays uppercase A for any hour before noon, and displays uppercase P for any hour between noon and 11:59 p.m. If this is the only character in a user-defined number format, use%t.
TT uses a 12-hour system and displays uppercase AM for any hour before noon, and an uppercase PM for any hour between noon and 11:59 p.m.
Y Displays the year (0-9) as a number without leading zeros. If this is the only character in a user-defined number format, use%y.
YY Displays the year, if applicable, in a two-digit number format with leading zeros.
YYY Displays the year in three-digit number format.
YYYY displays the year in four-digit number format.
Z Displays the time zone offset without leading zeros (for example,-8). If this is the only character in a user-defined number format, use%z.
ZZ shows the time zone offset with leading zeros (for example-08)
ZZZ Displays the full time zone offset (for example, -08:00)

NET get system Current time (reprint)

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.