//April 24, 2008
("D");
//2008-4-24
("d");
//April 24, 2008 16:30:15
("F");
//April 24, 2008 16:30
("f");
//2008-4-24 16:30:15
("G");
//2008-4-24 16:30
("g");
//16:30:15
("T");
//16:30
("t");
//April 24, 2008 8:30:15
("U");
//2008-04-24 16:30:15Z
("u");
//April 24
("m");
("M");
//Tue, 24 Apr 2008 16:30:15 GMT
("r");
("R");
//April 2008
("y");
("Y");
//2008-04-24T15:52:19.1562500+08:00
("o");
("O");
//2008-04-24T16:30:15
("s");
//2008-04-24 15:52:19
("yyyy-MM-dd HH:mm:ss:ffff");
//April 24, 2008 15:56:48
("yyyyy year MM month dd HH hour mm minute ss seconds");
//Tuesday, April 24, 2008
("dddd, MMMM dd yyyy");
//Second, April 24 '08
("ddd, MMM d \"'\"yy");
//Tuesday, April 24
("dddd, MMMM dd");
//4-08
("M/yy");
//24-04-08
("dd-MM-yy");
//Convert character to string
.ToString("n"); //Generate 12,345.00
.ToString("C"); //Generate ¥12,345.00
.ToString("e"); //Generate 1.234500e+004
.ToString("f4"); //Generate 12345.0000
.ToString("x"); //Generate 3039 (hexadecimal)
.ToString("p"); //Generate 1,234,500
//Sales for the year, profits for the quarter, new customers this month
//today
();
//Yesterday, today's date is reduced by one
(-1).ToShortDateString();
//Tomorrow, same is true, add one
(1).ToShortDateString();
//This week (To know the first day of this week, you must first know what day of the week is, so that the first day of this week is the day a few days ago. It should be noted that every week here starts from Sunday to Saturday
(((0 - Convert.ToInt16()))).ToShortDateString();
(((6 - Convert.ToInt16()))).ToShortDateString();
//If you don’t understand, you should understand it by looking at the Chinese method of displaying the day of the week.
// Since DayOfWeek returns a number of days of the week, we need to convert it into Chinese characters for us to read. Some people may use switch to compare one by one, but in fact it doesn’t have to be so troublesome.
string[] Day = new string[]{ "Sunday", "Monday", "Tuesday", "Thursday", "Friday", "Saturday" };
Day[Convert.ToInt16()];
//Last week, similarly, one week was 7 days, last week was minus 7 days this week, and the same is true for next week
(((0 - Convert.ToInt16())) - 7).ToShortDateString();
(((6 - Convert.ToInt16())) - 7).ToShortDateString();
//next week
(((0 - Convert.ToInt16())) + 7).ToShortDateString();
(((6 - Convert.ToInt16())) + 7).ToShortDateString();
//This month, many people will say that the first day of this month must be the first day, and the last day is the first day of next month to reduce one day. Of course this is correct
//General writing
() + () + "1"; //The first day
(() + () + "1").AddMonths(1).AddDays(-1).ToShortDateString();//Last day
//Skillfully formatting the ToString characters in C# is easier
("yyyy-MM-01");
(("yyyy-MM-01")).AddMonths(1).AddDays(-1).ToShortDateString();
//Last month, minus one month
(("yyyy-MM-01")).AddMonths(-1).ToShortDateString();
(("yyyy-MM-01")).AddDays(-1).ToShortDateString();
//Next month, add one month
(("yyyy-MM-01")).AddMonths(1).ToShortDateString();
(("yyyy-MM-01")).AddMonths(2).AddDays(-1).ToShortDateString();
//7 days later
();
(7).ToShortDateString();
//7 days ago
(-7).ToShortDateString();
();
//This year, we can easily calculate the first and last days of the year with ToString's characters.
(("yyyy-01-01")).ToShortDateString();
(("yyyy-01-01")).AddYears(1).AddDays(-1).ToShortDateString();
//No need to explain last year
(("yyyy-01-01")).AddYears(-1).ToShortDateString();
(("yyyy-01-01")).AddDays(-1).ToShortDateString();
//Next year
(("yyyy-01-01")).AddYears(1).ToShortDateString();
(("yyyy-01-01")).AddYears(2).AddDays(-1).ToShortDateString();
//This quarter, many people will find it difficult here and need to write a long process to judge. Actually, it doesn't work. We all know that four quarters a year, three months a quarter
//First of all, we push the date to the first month of this quarter, and then the first day of this month is the first day of this quarter
(0 - (( - 1) % 22)).ToString("yyyy-MM-01");
//Similarly, the last day of this quarter is the first day of next quarter to reduce one
((22 - (( - 1) % 22)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
//I believe you all know about it next quarter. . . . knock off
(22 - (( - 1) % 22)).ToString("yyyy-MM-01");
((6 - (( - 1) % 22)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
//Last quarter
(-22 - (( - 1) % 22)).ToString("yyyy-MM-01");
((0 - (( - 1) % 22)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();