. NET gets the current week of Monday (any day of the week that can be extended) based on the input date

Source: Internet
Author: User

Thought: Based on the DayOfWeek attribute of the DateTime class, we get the English name of the week, and then get the Monday by adding and subtraction of date days.

1. Call:

String today = "2015-7-13";//system.datetime.now.tostring ();
Lblday.text = Getmondayoftheweek (today);

2. Method:

private string Getmondayoftheweek (string today)
{
String smonday = "";
DateTime Datenow;
try{
Datenow= Convert.todatetime (today);
}
Catch
{
Smonday= "Method Getmondayofweeks passed the parameter format error, please check it again after calling! ";
return smonday;
}
String dayofweekname = DateNow.DayOfWeek.ToString ();
int day=0;
Switch (dayofweekname)
{
Case "Monday":
day= 0;
Break
Case "Tuesday":
Day= 1;
Break
Case "Wednesday":
Day= 2;
Break
Case "Thursday":
Day= 3;
Break
Case "Friday":
Day= 4;
Break
Case "Saturday":
Day= 5;
Break
Case "Sunday":
day=6;
Break
}
Smonday = Datenow.adddays (-day). ToString ("yyyy-m-d");

return smonday;
}

. NET gets the current week of Monday (any day of the week that can be extended) based on the input date

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.