zoukankan      html  css  js  c++  java
  • C#对时间的操作

        //获取当前星期的开始日期和结束日期
        private void TimeBE(out string bDate, out string eDate)
        {
            string firstDateText = NowTime();
            DateTime firstDay = Convert.ToDateTime(firstDateText);
            double theday;
            if (firstDay.DayOfWeek == DayOfWeek.Sunday) { theday = 7; }
            else if (firstDay.DayOfWeek == DayOfWeek.Monday) { theday = 1; }
            else if (firstDay.DayOfWeek == DayOfWeek.Tuesday) { theday = 2; }
            else if (firstDay.DayOfWeek == DayOfWeek.Wednesday) { theday = 3; }
            else if (firstDay.DayOfWeek == DayOfWeek.Thursday) { theday = 4; }
            else if (firstDay.DayOfWeek == DayOfWeek.Friday) { theday = 5; }
            else { theday = 6; }
            double bday = -theday;
            double eday = 7 - theday;
            bDate = firstDay.AddDays(bday).ToString();
            eDate = firstDay.AddDays(eday).ToString();
        }
        //获取当前月份的第一天
        private DateTime GetFirstDayOfMonthTime()
        {
            return GetFirstDayOfMonth(DateTime.Now.Year, DateTime.Now.Month);
        }
        //获取当前月份的最后一天
        private DateTime GetLastDayOfMonthTime()
        {
            return GetLastDayOfMonth(DateTime.Now.Year, DateTime.Now.Month);
        }
        //获取当前日期
        private string NowTime()
        {
            return DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString();
        }
        //根据年份月份获取月份的第一天
        private DateTime GetFirstDayOfMonth(int Year, int Month)
        {
            return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-1");
        }
        //根据年份月份获取月份的最后一天
        private DateTime GetLastDayOfMonth(int Year, int Month)
        {
            int Days = DateTime.DaysInMonth(Year, Month);
            return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-" + Days.ToString());
        }
  • 相关阅读:
    codova 打包vue项目的坑
    vscode 开发wtl 笔记
    redis
    展开/收缩 ul
    ueditor
    xml
    NPOI
    滚动效果,有些浏览器不支持
    fileupload控件上传、文件下载
    excel函数
  • 原文地址:https://www.cnblogs.com/myssh/p/1530752.html
Copyright © 2011-2022 走看看