zoukankan      html  css  js  c++  java
  • 日期

     private void Form3_Load(object sender, EventArgs e)
            {
                comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
                comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
                comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
                for (int i =DateTime.Now.Year; i >1949; i--)
                {
                    comboBox1.Items.Add(i+"年");
                }
                dateTimePicker1.Format = DateTimePickerFormat.Custom;
                dateTimePicker1.CustomFormat = " ";
            }

            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                comboBox2.Items.Clear();
                for (int i = 1; i < 12; i++)
                {
                    comboBox2.Items.Add(i +"月");
                }
            }

            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                comboBox3.Items.Clear();
                string years = comboBox1.SelectedItem.ToString().Split(new char[] { '年' }, StringSplitOptions.RemoveEmptyEntries)[0];
                string month = comboBox2.SelectedItem.ToString().Split(new char[] { '月' }, StringSplitOptions.RemoveEmptyEntries)[0];
                int year = Convert.ToInt32(years);
                int yue = Convert.ToInt32(month);
                int day = 0;
                switch (yue)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        day = 31;
                        break;
                    case 2:
                        if (year % 400==00 || year % 4 == 0 && year % 100 != 0)
                        {
                            day = 29;
                        }
                        else
                        {
                            day = 28;
                        }
                        break;
                    default:
                        day=30;
                        break;

                }

                for (int i = 1; i <=day; i++)
                {
                    comboBox3.Items.Add(i + "日");
                }
            }

    //日期格式选择

            private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
            {


                dateTimePicker1.Format = DateTimePickerFormat.Short;
              string strData=  dateTimePicker1.Text;
              char[] str = { '/' };        
            string[] strResult=  strData.Split(str, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < strResult.Length; i++)
            {
                textBox1.Text = strResult[0] + "-" + strResult[1] + "-" + strResult[2];
               
            }
            }

  • 相关阅读:
    《秋日》 -- 程颢
    《安乐吟》 -- 邵雍
    《大学》笔记
    《跨越鸿沟》笔记
    庄子《齐物论》—— 方生方死、因是因非是对立统一规律的起源
    《饮酒(其五)》陶渊明
    《亲密关系》笔记
    《人生的智慧》笔记
    《历史的教训》笔记
    《格鲁夫给经理人的第一课》笔记
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5361169.html
Copyright © 2011-2022 走看看