string str = "2015年3月";
int firstIndex = str.IndexOf("年", );
int secondIndex = str.IndexOf("月", firstIndex + );
string month = str.Substring(firstIndex + , secondIndex - firstIndex - );
string year = str.Substring(, );
DateTime dt = DateTime.Now;
string[] time = dt.ToString().Split(new char[]{'/'});
string date = year + "/" + month + "/" + time[];
DateTime first = Convert.ToDateTime(date).AddDays( - Convert.ToDateTime(date).Day);
DateTime last=Convert.ToDateTime(date).AddDays( - Convert.ToDateTime(date).Day).AddMonths().AddDays(-);
//The first day of the month
Label1.Text = first.ToString();
//The last day of the month
Label2.Text = last.ToString();
//businessDays of the month(except on the weekend)
Label3.Text = getint(first, last).ToString();

getint 方法:

public int getint(DateTime firstDay, DateTime lastDay)
{
firstDay = firstDay.Date;
lastDay = lastDay.Date;
if (firstDay > lastDay)
throw new ArgumentException("Incorrect last day " + lastDay);
TimeSpan span = lastDay - firstDay;
int businessDays = span.Days + ;
int fullWeekCount = businessDays / ;
// find out if there are weekends during the time exceedng the full weeks
if (businessDays > fullWeekCount * )
{
// we are here to find out if there is a 1-day or 2-days weekend
// in the time interval remaining after subtracting the complete weeks
int firstDayOfWeek = firstDay.DayOfWeek == DayOfWeek.Sunday ? : (int)firstDay.DayOfWeek;
int lastDayOfWeek = lastDay.DayOfWeek == DayOfWeek.Sunday ? : (int)lastDay.DayOfWeek; if (lastDayOfWeek < firstDayOfWeek)
lastDayOfWeek += ;
if (firstDayOfWeek <= )
{
if (lastDayOfWeek >= )// Both Saturday and Sunday are in the remaining time interval
businessDays -= ;
else if (lastDayOfWeek >= )// Only Saturday is in the remaining time interval
businessDays -= ;
}
else if (firstDayOfWeek <= && lastDayOfWeek >= )// Only Sunday is in the remaining time interval
businessDays -= ;
}
// subtract the weekends during the full weeks in the interval
businessDays -= fullWeekCount + fullWeekCount;
return businessDays;
}

C# 根据年月获得此月第一天和最后一天,并计算工作日的更多相关文章

  1. 用js获取周、月第一天和最后一天(转载)

    var getCurrentWeek = function (day) { var days = ["周日", "周一", "周二", &q ...

  2. js 获取某月第一天和最后一天

    1.获取某月第一天和最后一天日期 function getDateByMonth (timeStamp) { let inDate = new Date(timeStamp) let year = i ...

  3. 获取某月第一天,最后一天的sql server脚本 【转】http://blog.csdn.net/chaoowang/article/details/9167969

    这是计算一个月第一天的SQL 脚本:    SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) --当月的第一天 SELECT DATEADD(mm, DA ...

  4. 获取某月第一天,最后一天的sql server脚本

    本文来自:http://blog.csdn.net/chaoowang/article/details/9167969 这是计算一个月第一天的SQL 脚本:   SELECT DATEADD(mm, ...

  5. C# DateTime 月第一天和最后一天 取法

    取得某月和上个月第一天和最后一天的方法 /// <summary> /// 取得某月的第一天 /// </summary> /// <param name="d ...

  6. asp编程中获取上下两个月第一天和最后一天的代码

    经常在asp编程遇到要获取上个月第一天和最后一天的日期,获取下个月第一天和最后一天的日期.这里总结了一下,将这些asp代码全部列出来了,以便以后遇到的时候使用.    上个月第一天:<%=dat ...

  7. sql 特殊时间值 第一天或最后一天 无计算错误

    DECLARE @dt datetimeSET @dt=GETDATE() DECLARE @number intSET @number=3 --1.指定日期该年的第一天或最后一天--A. 年的第一天 ...

  8. WinForm------DateTime获取月第一天和最后一天取法

    转载: http://blog.csdn.net/livening/article/details/6049341/ 代码: /// <summary> /// 取得某月的第一天 /// ...

  9. java时间计算,获取某月第一天和最后一天

    //获取前月的第一天 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); //获取当前月第一天: Calendar ...

随机推荐

  1. js的for in循环和java里的foreach循环的差别

    js里的for in循环定义例如以下: for(var variable in obj) { ... } obj能够是一个普通的js对象或者一个数组.假设obj是js对象,那么variable在遍历中 ...

  2. mysql跟踪提交的SQL语句

    http://www.cnblogs.com/wuyifu/p/3328024.html

  3. 关于VS 2010 RDLC 报表的详细使用说明

    各位技术屌丝们好, 之前我用了很长一段时间通过不断的研究揣摩,终于把RDLC报表给搞透了,今天跟大家做个总结,希望能够帮助到大家. 需求分析 我想把datagridview 中的数据打印出来. 首先 ...

  4. java学习之部分笔记

    1.枚举类型 2.String的方法Index的用法.StringBuffer 的用法.Math的用法.Date类 3.用abstract修饰的类就是抽象类.抽象方法不能有主体.抽象类中,可以有抽象方 ...

  5. Android Studio Errors

    1.The import org.apache.http.client; tip: cannot be resolved; resolve: add this line in build.gradle ...

  6. JavaScript面向对象精要

    来自:淡忘~浅思. 链接:http://www.ido321.com/1585.html 和 http://www.ido321.com/1586.html 数据类型   在JavaScript中,数 ...

  7. SQL Server Schema

    SQL查询是引用表时,需要为其制定模式名. 在数据库的术语中,模式就是名称空间.这种方式可以把相同特性的对象组合到一个共同的名称空间中.模式也可以保护对象,所以DBA可以给模式授予显示权限. 例如,D ...

  8. 安装apache mysql 论坛(一)

    安装mysql: 注: yum文件配置: 检查配置文件: 启动:service mysqld start 查询表: apache安装 启动: 查看端口: 欢迎界面: 如果服务了4000次,会主动销毁, ...

  9. Composer配置中国镜像

    用法: 有两种方式启用本镜像服务: 将以下配置信息添加到 Composer 的配置文件 config.json 中(系统全局配置).见“例1” 将以下配置信息添加到你的项目的 composer.jso ...

  10. MVC4商城项目二:用户身份验证的实现

    用户身份验证,依赖于 forms 身份验证类:FormsAuthentication,它是一串加密的cookie 来实现对控制器访问限制和登陆页面的访问控制.它在浏览器端是这样子的: 需求:我们要实现 ...