Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从datetimepicker到textbox的时间总和_C# - Fatal编程技术网

C# 从datetimepicker到textbox的时间总和

C# 从datetimepicker到textbox的时间总和,c#,C#,在windows窗体中的c#中,我使用了仅限五个时间选择器的时间格式。 这四个值写在4文本框中。 我需要在第五个文本框或时间选择器中查看PPreceidenti 4的小时总数 此代码错误: TimeSpan result = this.dateTimePicker22.Value + this.dateTimePicker23.Value + this.dateTimePicker24.Value + this.dateTimePicker25.Value + this.dateTimePick

在windows窗体中的
c#
中,我使用了仅限五个时间选择器的时间格式。 这四个值写在4文本框中。 我需要在第五个
文本框
时间选择器
中查看PPreceidenti 4的小时总数

此代码错误:

TimeSpan result = this.dateTimePicker22.Value + this.dateTimePicker23.Value + this.dateTimePicker24.Value + this.dateTimePicker25.Value + this.dateTimePicker26.Value);
this.textBox21.Text = result.ToString();
我计算工作时间,因此:

    private void Calcolaweek1()
    {
        textBox23.MaxLength = 5;
        DeleteChars();
        if (textBox23.Text.Length == 2)
            textBox23.Text += ":";

        textBox23.SelectionStart = textBox23.Text.Length;

        DateTime time = new DateTime();
        this.textBox23.Text = time.ToString("HH:mm");


        if ((textBox1.Text.Length > 0) && (textBox2.Text.Length > 0) && (textBox3.Text.Length > 0) && (textBox4.Text.Length > 0))
        {
            textBox23.MaxLength = 5;
            TimeSpan result = this.dateTimePicker4.Value - this.dateTimePicker1.Value - (this.dateTimePicker3.Value - this.dateTimePicker2.Value);
            this.textBox23.Text = result.ToString();

        }
        else if ((string.IsNullOrEmpty(textBox2.Text)) || (string.IsNullOrEmpty(textBox3.Text)))
        {

            TimeSpan result1 = this.dateTimePicker4.Value - this.dateTimePicker1.Value;
            this.textBox23.Text = result1.ToString();
        }

    }
我必须计算每天所有工作时间的总和



为什么要使用++对不起。我错了。我只使用“+”你有什么例外?增加时间有什么意义?如果求和
12:00:00
23:59:00
,您会期望什么?运算符“+”不能应用于system.DateTime类型的操作数。为什么要使用++对不起。我错了。我只使用“+”你有什么例外?增加时间有什么意义?如果求和
12:00:00
23:59:00
,您会期望什么?运算符“+”不能应用于system.DateTime类型的操作数我可以有小时和分钟吗?嗯,你说的是什么意思?在你的问题中,你说你想添加小时和分钟,DateTimePicker控件在我的回答中有这些属性。小时是你的HH,分钟是你的mm。你还需要知道什么?我有五个datetimepicker“07:38:00”,我想得到“38:10:00”。你的意思是说你有第五个datetimepicker,你想计算总和(206)并以HH:mm格式显示它。我说的对吗?是的!!正确地但是格式是HH:mm。看,我能有小时和分钟吗?嗯,你说的是什么意思?在你的问题中,你说你想添加小时和分钟,DateTimePicker控件在我的回答中有这些属性。小时是你的HH,分钟是你的mm。你还需要知道什么?我有五个datetimepicker“07:38:00”,我想得到“38:10:00”。你的意思是说你有第五个datetimepicker,你想计算总和(206)并以HH:mm格式显示它。我说的对吗?是的!!正确地但是格式是HH:mm。看看
private void btnCalculate_Click(object sender, EventArgs e)
{
   try
   {
      int hours = picker1.Value.Hour % 12 +
                  picker2.Value.Hour % 12 +
                  picker3.Value.Hour % 12 +
                  picker4.Value.Hour % 12 +
                  picker5.Value.Hour % 12;

      int minutes = picker1.Value.Minute % 60 +
                    picker2.Value.Minute % 60 +
                    picker3.Value.Minute % 60 +
                    picker4.Value.Minute % 60 +
                    picker5.Value.Minute % 60;

      TimeSpan fromMinutes = TimeSpan.FromMinutes(minutes);
      var ts = hours + fromMinutes.Hours + ":" + fromMinutes.Minutes;
   }
   catch (Exception)
   {
      throw;
   }
}