C # gets this week, month, year, etc time and datetime date formatting based on the current time

Source: Internet
Author: User

1DateTime dt = DateTime.Now;//Current Time2 3DateTime startweek = dt. AddDays (1-Convert.ToInt32 (dt. Dayofweek.tostring ("D")));//this Monday4DateTime Endweek = Startweek.adddays (6);//this Sunday5 6DateTime startmonth = dt. AddDays (1-DT. Day);//Early this month7DateTime Endmonth = startmonth.addmonths (1). AddDays (-1);//Month End8 9DateTime startquarter = dt. AddMonths (0-(dt. Month-1) %3). AddDays (1-DT. Day);//At the beginning of the quarterTenDateTime Endquarter = startquarter.addmonths (3). AddDays (-1);//At the end of the quarter One  ADateTime startyear =NewDateTime (dt. Year,1,1);//early this year -DateTime endyear =NewDateTime (dt. Year, A, to);//End of year

DateTime date Formatting

1DateTime.Now.ToString ();//2016/5/9 13:09:55 Short Date long time2DateTime.Now.ToString ("D");//2016/5/9 Short Date3DateTime.Now.ToString ("D");//May 9, 2016 long date4DateTime.Now.ToString ("F");//May 9, 2016 13:09 short time long Date5DateTime.Now.ToString ("F");//May 9, 2016 13:09:55 long date long time6DateTime.Now.ToString ("g");//2016/5/9 13:09 Short Date short time7DateTime.Now.ToString ("G");//2016/5/9 13:09:55 Short Date long time8DateTime.Now.ToString ("T");//13:09 short time9DateTime.Now.ToString ("T");//13:09:55 Long hoursTenDateTime.Now.ToString ("m");//May 9 OneDateTime.Now.ToString ("M");//May 9 ADateTime.Now.ToString ("R");//Mon, 13:09:55 GMT -DateTime.Now.ToString ("R");//Mon, 13:09:55 GMT -DateTime.Now.ToString ("y");//May 2016 theDateTime.Now.ToString ("Y");//May 2016

C # gets this week, month, year, etc time and datetime date formatting based on the current time

Related Article

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.