• c#选择日期


    using System;
    using System.Windows.Forms;
    
    namespace DateDemo
    {
        public partial class Form1 : Form
        {
            private int _currentYearIndex;
            private int _currentMonthIndex;
            private const int StartYear = 1949;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                DateTime today = DateTime.Today;
                for (var i = today.Year; i >=StartYear; i--)
                {
                    cbYear.Items.Add(i);
                }
                for (var i = 1; i < 13; i++)
                {
                    cbMonth.Items.Add(i);
                }
    
                for (var i = 1; i < GetDays(today.Year, today.Month); i++)
                {
                    cbDay.Items.Add(i);
                }
    
                cbYear.SelectedIndex = 0;
                cbMonth.SelectedIndex = today.Month - 1;
                cbDay.SelectedIndex = today.Day - 1;
            }
    
            private int GetDays(int year, int month)
            {
                var days = 0;
                switch (month)
                {
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        days = 30;
                        break;
    
                    case 2:
                        days = IsLeapYear(year) ? 29 : 28;
                        break;
    
                    default:
                        days = 31;
                        break;
                }
    
                return days;
            }
    
            public static bool IsLeapYear(int year)
            {
                return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;
            }
    
            private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
            {
                _currentYearIndex = cbYear.SelectedIndex;
                int y = DateTime.Today.Year- cbYear.SelectedIndex;
                int m = _currentMonthIndex + 1;
                //            MessageBox.Show(y+"  "+m);
                SettingCbDay(y, m);
                cbDay.SelectedIndex = 0;
            }
    
            private void SettingCbDay(int y, int m)
            {
                cbDay.Items.Clear();
                for (var i = 1; i <= GetDays(y, m); i++)
                {
                    cbDay.Items.Add(i);
                }
            }
    
            private void cbMonth_SelectedIndexChanged(object sender, EventArgs e)
            {
                _currentMonthIndex = cbMonth.SelectedIndex;
                int y = DateTime.Today.Year - cbYear.SelectedIndex;
                int m = cbMonth.SelectedIndex + 1;
                //            MessageBox.Show(y + "  " + m);
                SettingCbDay(y, m);
                cbDay.SelectedIndex = 0;
            }
        }
    }
  • 相关阅读:
    Java编译器API简介
    liblinear和libsvm区别
    spark和hadoop比较
    maxout激活函数
    FTRL算法
    NLP里面好的学习资料
    阿里妈妈MLR模型(论文)
    FM的推导原理--推荐系统
    GBDT+LR simple例子
    深度学习最全优化方法---来源于知乎
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7619953.html
Copyright © 2020-2023  润新知