C # obtain the week start time/Month start time/year start time of the specified time

Source: Internet
Author: User

Datetime. Now = 2009-7-16 5:20:56

// Today

Datetime. Now. Date. tostring ();
"2009-7-16 0:00:00"

// Week start date

Datetime. Now. Date. adddays (-(INT) (datetime. Now. dayofweek) + 1). tostring ();
{0:00:00}
Datetime. Now. Date. adddays (7-(INT) (datetime. Now. dayofweek). tostring ();
{0:00:00}

// Start date of the month
New datetime (datetime. Now. Year, datetime. Now. month, 1). tostring ();
{0:00:00}

New datetime (datetime. now. date. year, datetime. now. date. month, datetime. daysinmonth (datetime. now. date. year, datetime. now. date. month )). tostring ();
"0:00:00"

// Start date of the year
New datetime (datetime. Now. Date. Year, 1, 1). tostring ();
{0:00:00}
New datetime (datetime. Now. Date. year, 12, datetime. daysinmonth (datetime. Now. Date. Year, datetime. Now. Date. month). tostring ();
{0:00:00}

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.