ASP.net gets the current time, and the string is formatted for conversion
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 a format like 2005-02-18 DateTime.Now.ToString ("Hh:mm:ss"); take time and get a format like 10:45:30 Format 4.DateTime t1 = DateTime.Parse (DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss")), and get format 5, such as 2005-02-18 10:45:30 . datetime t2 = t1. AddDays (7); T2 is more than T1 7 days, if less 7 days is datetime t2 = t1. AddDays (-7); Other units are similar. Show M/d/yy 12/7/58 d-mmm 7-dec d-mmmm-yy 7-december-58 D MMMM 7 December MMMM yy December 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: 1. (:) The time separator. In some locales, you can use other characters to represent the time separator. 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 LocaleID value of the system. 2. (/) Date separator. In some locales, you can use other characters to represent a date separator. The date separator separates day, month, and year when formatting date values. The actual characters used as date separators in the formatted output are determined by your locale settings. 3. (%) Used to indicate that characters should be read in one-letter format, regardless of the letter followed. Also used to indicate that a single letter format should be read in a user-defined format. For more information, see the following section. 4.D Displays the day as a number with no leading zeros (for example, 1). If this is a user-defined numberA unique character in the word format, use%d. DD Displays the day as a number with a leading zero (for example, 01). DDD Displays the day as an abbreviated form (for example, Sun). DDDD Displays the day as a full name (for example, Sunday). 5. M Displays the month as a number without a leading zero (as indicated in January as 1). If this is the only character in the user-defined number format, use%m. MM Displays the month as a number with a leading zero (for example, 01/12/01). MMM Displays the month as an abbreviated form, such as a few. MMMM Displays the month as the full month name (for example, January). 6. GG Displays the era/era string (for example, A.D.) 7. h uses a 12-hour system to display hours as a number without a leading zero (for example, 1:15:15 PM). If this is the only character in the user-defined number format, use%h. HH uses a 12-hour system to display hours as numbers with leading zeros (for example, 01:15:15 PM). H displays the hour as a number with no leading zeros (for example, 1:15:15) using a 24-hour system. If this is the only character in the user-defined number format, use%H. HH uses a 24-hour system to display hours as a number with a leading zero (for example, 01:15:15). 8. m displays the minute as a number without a leading zero (for example, 12:1:15). If this is the only character in the user-defined number format, use%m. MM Displays the minute as a number with a leading zero (for example, 12:01:15). 9. s Displays the second as a number without a leading zero (for example, 12:15:5). If this is the only character in the user-defined number format, use%s. SS Displays the second as a number with a leading zero (for example, 12:15:05).  10.F displays the fraction of seconds. For example, FF will display exactly 1% seconds, and FFFF will be displayed exactly to 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 the user-defined number format, use%f. 11. t uses a 12-hour system and displays an uppercase a for any hour prior to noon, with an uppercase P for any hour between noon and 11:59 p.m. If this is the only character in the user-defined number format, use%t. TT uses a 12-hour system and displays an uppercase AM for any hour before noon, and an uppercase PM for any hour between noon and 11:59 p.m. 12. y Displays the year (0-9) as a number with no leading zeros. If this is the only one in the user-defined number formatcharacters, please use%y. YY Displays the year in two-digit format with a leading zero, if applicable. YYY Displays the year in three-digit number format. YYYY displays the year in four-digit number format. 13. Z Displays the time zone offset (for example, 8) without a leading zero. If this is the only character in the user-defined number format, use%z. ZZ Displays a time zone offset with a leading zero (for example, -08) ZZZ displays the full time zone offset (for example, -08:00)