专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > J#

依据年、月、周、求本月的起始日和结束日

发布时间:2011-06-24 18:56:17 文章来源:www.iduyao.cn 采编人员:星星草
根据年、月、周、求本月的起始日和结束日!
根据年、月、周、求本月的起始日和结束日!

根据年、月、周、求本月的起始日和结束日!

根据年、月、周、求本月的起始日和结束日!
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(GetStartDate(2011, 8, 2));
            Console.WriteLine(GetEndDate(2011, 8, 2));
        }

        static DateTime GetStartDate(int year, int month, int week)
        {
            if (week < 1) return default(DateTime);
            if (week == 1)
                return new DateTime(year, month, 1);
            else
                return GetEndDate(year, month, week - 1).AddDays(1);
        }

        static DateTime GetEndDate(int year, int month, int week)
        {
            if (week < 1) return default(DateTime);
            DateTime dt = new DateTime(year, month, 1);
            if (week == 1) 
                return new DateTime(year, month, 1).AddDays(6 - (int)(new DateTime(year, month, 1)).DayOfWeek);
            else
                return GetEndDate(year, month, week - 1).AddDays(7);
        }
    }
}
2011-8-7 0:00:00
2011-8-13 0:00:00
Press any key to continue . . .
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: