// 2008年4月24日
System.DateTime.Now.ToString( " D " );
// 2008-4-24
System.DateTime.Now.ToString( " d " );
// 2008年4月24日 16:30:15
System.DateTime.Now.ToString( " F " );
// 2008年4月24日 16:30
System.DateTime.Now.ToString( " f " );
// 2008-4-24 16:30:15
System.DateTime.Now.ToString( " G " );
// 2008-4-24 16:30
System.DateTime.Now.ToString( " g " );
// 16:30:15
System.DateTime.Now.ToString( " T " );
// 16:30
System.DateTime.Now.ToString( " t " );
// 2008年4月24日 8:30:15
System.DateTime.Now.ToString( " U " );
// 2008-04-24 16:30:15Z
System.DateTime.Now.ToString( " u " );
// 4月24日
System.DateTime.Now.ToString( " m " );
System.DateTime.Now.ToString( " M " );
// Tue, 24 Apr 2008 16:30:15 GMT
System.DateTime.Now.ToString( " r " );
System.DateTime.Now.ToString( " R " );
// 2008年4月
System.DateTime.Now.ToString( " y " );
System.DateTime.Now.ToString( " Y " );
// 2008-04-24T15:52:19.1562500+08:00
System.DateTime.Now.ToString( " o " );
System.DateTime.Now.ToString( " O " );
// 2008-04-24T16:30:15
System.DateTime.Now.ToString( " s " );
// 2008-04-24 15:52:19
System.DateTime.Now.ToString( " yyyy-MM-dd HH:mm:ss:ffff " );
// 2008年04月24 15时56分48秒
System.DateTime.Now.ToString ( "yyyy, MM month when dd HH mm ss a");
// Tuesday April 2008 24
System.DateTime.Now.ToString ( "dddd, MMMM dd YYYY");
// two April '08 24
System.DateTime.Now.ToString ( "ddd, MMM D \" ' \ "YY");
// Tuesday, April 24
System.DateTime.Now.ToString ( "dddd, dd MMMM");
// 4-08
System.DateTime.Now.ToString ( "M / YY");
/ / 24-04-08
System.DateTime.Now.ToString ( "the MM-dd-YY");
// converted into character strings
12345 .ToString ( "n"); // generating 12,345.00
12345 .ToString ( " C "); // 12,345.00 generating ¥
12345 .ToString (" E "); // + 004 generates 1.234500e
12345 .ToString (" F4 "); // generate 12345.0000
12345 .ToString (" X "); // generated 3039 (hexadecimal)
12345.ToString ( "p"); // generate 1,234,500
// sales this year, profits in the quarter, new customers this month
// Today
DateTime.Now.Date.ToShortDateString ();
// yesterday, it is today's date minus one
DateTime.Now.AddDays (- 1) .ToShortDateString ();
// tomorrow, empathy, plus a
DateTime.Now. AddDays (1) .ToShortDateString ();
// this week (you know the first day of the week he will have to know that today is the day of the week, so that is the first day of the week a few days ago that day, pay attention each week here was from Sunday to Saturday start stop
DateTime.Now.AddDays (Convert.ToDouble ((0 - Convert.ToInt16 (DateTime.Now.DayOfWeek)))) ToShortDateString ();.
the DateTime.Now. AddDays (Convert.ToDouble ((6 - Convert.ToInt16 (DateTime.Now.DayOfWeek)))) ToShortDateString ();.
// If you do not understand, look at what Chinese method of displaying days of the week should understand
// Because DayOfWeek returns the numbers of the week, we want to convert to facilitate the characters we read that some people may use the switch to control one by one, in fact, not so much trouble in the
string [] Day = new string [ ] { " Sunday " , " Monday Tuesday Wednesday Thursday" , " Five "," Saturday "};
Day [Convert.ToInt16 (DateTime.Now.DayOfWeek)];
// Last week, the same token, one week is seven days, last week, is minus seven days this week, next week is the same
DateTime.Now.AddDays (Convert .ToDouble ((0 - Convert.ToInt16 (DateTime.Now.DayOfWeek))) -. 7) .ToShortDateString ();
DateTime.Now.AddDays (Convert.ToDouble ((. 6 - Convert.ToInt16 (DateTime.Now.DayOfWeek)) ) -. 7) .ToShortDateString ();
// week
DateTime.Now.AddDays (Convert.ToDouble ((0 - Convert.ToInt16 (DateTime.Now.DayOfWeek))) +. 7) .ToShortDateString ();
the DateTime.Now. AddDays (Convert.ToDouble ((6 - Convert.ToInt16 (DateTime.Now.DayOfWeek))) + 7) .ToShortDateString ();
// this month, many people will say that the first day of the month thing is definitely No. 1, One is the last day of next month minus one day. This is of course
// general wording
DateTime.Now.Year.ToString () + DateTime.Now.Month.ToString () + "1"; // day
DateTime.Parse (DateTime.Now.Year.ToString () + DateTime.Now.Month.ToString ( ) + "1") .AddMonths (1) .AddDays (- 1) .ToShortDateString (); // the last day
// using C # in ToString character formatting easier
DateTime.Now.ToString ( "yyyy-MM-01");
. DateTime.Parse (DateTime.Now.ToString ( "yyyy-MM-01")) AddMonths (1) .AddDays (- 1) .ToShortDateString ();
// Last month, minus a month
. DateTime.Parse (DateTime.Now.ToString ( "yyyy- MM-01")) AddMonths (- 1) .ToShortDateString () ;
DateTime.Parse (DateTime.Now.ToString ( "yyyy-MM-01")) AddDays (- 1) .ToShortDateString ();.
// next month, adding to a month
DateTime.Parse (DateTime.Now.ToString ( "yyyy-MM-01" )) AddMonths (1) .ToShortDateString ().;
The DateTime.Parse (DateTime.Now.ToString ( "the MM-YYYY-01")) AddMonths (2) .AddDays (-. 1) .ToShortDateString ();.
//. 7 days
DateTime.Now.Date.ToShortDateString ();
the DateTime .Now.AddDays (7) .ToShortDateString ();
// 7 days before
DateTime.Now.AddDays (- 7) .ToShortDateString ();
DateTime.Now.Date.ToShortDateString ();
// this year, with the character format ToString we are also of the easily calculated first and last day of the year
. DateTime.Parse (DateTime.Now.ToString ( "yyyy-01-01")) ToShortDateString ();
DateTime.Parse (DateTime.Now.ToString ( " 01-01-yyyy ")) AddYears (1) .AddDays (- 1) .ToShortDateString ();.
// last year, do not have to explain it
DateTime.Parse (DateTime.Now.ToString (" yyyy-01-01 . ")) AddYears (- 1 ) .ToShortDateString ();
. DateTime.Parse (DateTime.Now.ToString ( "yyyy-01-01")) AddDays (- 1) .ToShortDateString ();
// next year
DateTime.Parse (DateTime.Now.ToString ( "yyyy-01-01 ")) AddYears (. 1) .ToShortDateString ();.
the DateTime.Parse (DateTime.Now.ToString (." YYYY-01-01 ")) AddYears (2) .AddDays (-. 1) .ToShortDateString ();
// during the quarter, many people will find difficulty here, you need to write a long process to judge. In fact do not, we all know the four quarters of the year, a quarter three months
// First we put the date of the first month of the quarter to push, and then the first day of the month is the first day of the quarter
DateTime . .Now.AddMonths (0 - ((DateTime.Now.Month - 1)% 22)) ToString ( "yyyy-MM-01");
// Similarly, the first day of the last day of the quarter next quarter Save a
DateTime.Parse (DateTime.Now.AddMonths (22 - (( DateTime.Now.Month -. 1)% 22)) ToString ( "yyyy-MM-01")) AddDays. (- 1) .ToShortDateString () ;
// next quarter, I believe you all know. . . . knock off
DateTime.Now.AddMonths( 22 - ((DateTime.Now.Month - 1 ) % 22 )).ToString( " yyyy-MM-01 " );
DateTime.Parse(DateTime.Now.AddMonths( 6 - ((DateTime.Now.Month - 1 ) % 22 )).ToString( " yyyy-MM-01 " )).AddDays( - 1).ToShortDateString();
// 上季度
DateTime.Now.AddMonths( - 22 - ((DateTime.Now.Month - 1 ) % 22 )).ToString( " yyyy-MM-01 " );
DateTime.Parse(DateTime.Now.AddMonths( 0 - ((DateTime.Now.Month - 1 ) % 22 )).ToString( " yyyy-MM-01 " )).AddDays( - 1).ToShortDateString();
Reference: https://blog.csdn.net/linjcai/article/details/81119709