• 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());
        }
  • 相关阅读:
    IOS开发-CALayer和UIView详细汇总
    IOS开发-第三方SDWebImage下载网络图片的使用
    解决TalbleView头部或底部子控件不显示问题
    node.js http.get 和http.post 数据
    Node.js Express 获取request原始数据
    个人开发者做一款Android App需要知道的事情
    个人开发者的酸甜苦辣
    码农的福利来了, 编程在线Androd 客户端上线了
    console使用技巧
    AngularJS 常用语法
  • 原文地址:https://www.cnblogs.com/myssh/p/1530752.html
Copyright © 2020-2023  润新知