c\#에서 DateTime.Now 함수 의 사용 에 대한 상세 한 설명

6684 단어 c#datetime.now

//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 dd HH mm ss ");
     // , 24 2008
     System.DateTime.Now.ToString("dddd, MMMM dd yyyy");
     // , 24 '08
     System.DateTime.Now.ToString("ddd, MMM d \"'\"yy");
     // , 24
     System.DateTime.Now.ToString("dddd, MMMM dd");
     //4-08
     System.DateTime.Now.ToString("M/yy");
     //24-04-08
     System.DateTime.Now.ToString("dd-MM-yy");
    //
.ToString("n");  // 12,345.00
.ToString("C"); // ¥12,345.00
.ToString("e"); // 1.234500e+004
.ToString("f4"); // 12345.0000
.ToString("x"); // 3039 (16 )
.ToString("p"); // 1,234,500
     // 、 、
   //
     DateTime.Now.Date.ToShortDateString();
     // ,
     DateTime.Now.AddDays(-1).ToShortDateString();
     // , ,
     DateTime.Now.AddDays(1).ToShortDateString();
     // ( , ,
     DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
     DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
     // ,
     // DayOfWeek , , switch ,             
     string[] Day = new string[]{ " ", " ", " ", " ", " ", " ", " " };
     Day[Convert.ToInt16(DateTime.Now.DayOfWeek)];
     // , , 7 , 7 ,
     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();
     //
     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();
     // , 1 , 。
     //
     DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1"; //
     DateTime.Parse(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + "1").AddMonths(1).AddDays(-1).ToShortDateString();//
     // C# ToString
     DateTime.Now.ToString("yyyy-MM-01");
     DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(1).AddDays(-1).ToShortDateString();
     // ,
     DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(-1).ToShortDateString();
     DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
     // ,
     DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(1).ToShortDateString();
     DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(2).AddDays(-1).ToShortDateString();
     //7
     DateTime.Now.Date.ToShortDateString();
     DateTime.Now.AddDays(7).ToShortDateString();
     //7
     DateTime.Now.AddDays(-7).ToShortDateString();
     DateTime.Now.Date.ToShortDateString();
     // , ToString
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).ToShortDateString();
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).AddYears(1).AddDays(-1).ToShortDateString();
     // ,
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).AddYears(-1).ToShortDateString();
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).AddDays(-1).ToShortDateString();
     //
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).AddYears(1).ToShortDateString();
     DateTime.Parse(DateTime.Now.ToString("yyyy-01-01")).AddYears(2).AddDays(-1).ToShortDateString();
     // , , 。 , ,
     // ,
     DateTime.Now.AddMonths(0 - ((DateTime.Now.Month - 1) % 22)).ToString("yyyy-MM-01");
     // ,
     DateTime.Parse(DateTime.Now.AddMonths(22 - ((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(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();

좋은 웹페이지 즐겨찾기