zoukankan      html  css  js  c++  java
  • 星期几以及周,月份天数的计算(共用方法)

            #region 计算星期几
            /// <summary>
             ///  //: 星期日至星期六的值为0-6 
             /// </summary>
             /// <param name="year"></param>
             /// <param name="month"></param>
             /// <param name="day"></param>
             /// <returns></returns>   
            public static int GetWeeksOfDate(int year, int month, int day)  
            {
                return GetWeeksOfDate(new DateTime(year, month, day));
            }
    
            public static int GetWeeksOfDate(DateTime time)
            {
                DayOfWeek d = time.DayOfWeek;
                return Convert.ToInt32(d);  
            }
    
            public static string GetWeeksOfDateForChinese(DateTime time)
            {
                int week = GetWeeksOfDate(time);
                string strWeek ="";
                if (week == 0)
                {
                    strWeek = "";
                }
                else {
                    strWeek =Tools.Number2Chinese(week);
                }
                return "" + strWeek;
            }
            /// <summary>
            /// 星期一至星期日的值为1-7 
            /// </summary>
            /// <param name="time"></param>
            /// <returns></returns>
            public static int GetNumOfWeeks(DateTime time)
            {
                int t=GetWeeksOfDate(time);
                if(t==0)
                {
                    t = 7;
                }
                return t;
            }
            #endregion 
     #region 获取指定年月的天数
            /// <summary>
            /// 获取指定年月的天数 
            /// </summary>
            /// <param name="year"></param>
            /// <param name="month"></param>
            /// <returns></returns> 
            public static int GetDaysOfMonth(int year, int month)  
            {  
                DateTime dtCur = new DateTime(year, month, 1);  
                int days = dtCur.AddMonths(1).AddDays(-1).Day;  
                return days;
            }
            #endregion 
  • 相关阅读:
    Java基础面试题附答案 81-100(五)
    css练习--抽屉作业
    css
    HTML 快速入门
    selectors 模块完成文件上传下载功能
    IO 模型
    进程 线程 协程
    socket套接字
    异常处理
    面向对象
  • 原文地址:https://www.cnblogs.com/hugeboke/p/11574817.html
Copyright © 2011-2022 走看看