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. swfobject.js 2.2简单使用方法

    swfobject.js 2.2简单使用方法 官方网址介绍http://code.google.com/p/swfobject/wiki/documentation 用法:html部分<div ...

  2. 黑马程序员——java基础之文件复制

    ---------------------- ASP.Net+Unity开发..Net培训.期待与您交流!---------------------- <a href="http:// ...

  3. 谈谈javascript的函数表达式及其应用

    我们都知道定义函数的方式有两种,一种是函数声明,另外一种就是函数表达式. 函数声明 语法为:function关键字后跟函数名.例如: function functionName(arg0) { //函 ...

  4. Hibernate 查询:HQL查询(Hibernate Query Languge)

    HQL是一种面向对象的查询语言,其中没有表和字段的概念,只有类,对象和属性的概念. 使用HQL查询所有学生: public static void main(String[] args) { Sess ...

  5. USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)

    这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...

  6. 在world中批量调整图片的大小

    1.Alt+F8调出vb宏  创建一个宏名字,setsize 粘贴代码后保存关闭. Sub setsize() ' ' setsize 宏 ' ' Dim iSha As InlineShape Fo ...

  7. java口算器

    package dd;import javax.swing.*; import java.awt.*;import java.awt.event.*;class Main extends JFrame ...

  8. mySql-数据库之存储过程学习总结

    之前在工作中总是听别人提到存储过程,觉得是个很高深的东西,利用工作之余,看了下相关的知识,现将学习知识总结如下,希望可以为刚学习的人提供些许帮助. 开发环境:Navicat For Mysql. My ...

  9. 简单的JQuery top返回顶部

    一个最简单的JQuery Top返回的代码,Mark一下: HTML如下: <div id="backtop"> <a href="javascript ...

  10. git 快速使用(本地仓库同步到远程仓库)

    学git一段时间,可惜公司用的是svn,平时少用,又忘了,总结一下,免得下次又得重新学习.得多多用才是正道! 一.  将本地的提交到网上git仓库 1.在git创建仓库                ...