Correct format for TimeSpan
Hi. I need help. I am working on making a simple alarm clock and I want to get all the information from the two NumericUpDown controls and one button. I had limit the hours between 1-12 and limited minutes to 0-59, and set my button to change the text from AM-PM or PM to AM. Here's my code:
Code:
public TimeSpan tsTime;
private void nHour_ValueChanged(object sender, System.EventArgs e)
{
if(nHour.Value > 12)
{
nHour.Value = 1;
}
if(nHour.Value == 0)
{
nHour.Value = 12;
}
tsTime = TimeSpan.Parse(nHour.ToString()+":"+nMinute.ToString()+":00");
}
private void btnPMAM_Click(object sender, System.EventArgs e)
{
if(btnPMAM.Text == "AM")
{
btnPMAM.Text = "PM";
}
else
{
btnPMAM.Text = "AM";
}
tsTime = TimeSpan.Parse(nHour.ToString()+":"+nMinute.ToString()+":00");
}
private void nMinute_ValueChanged(object sender, System.EventArgs e)
{
if(nMinute.Value > 59)
{
nMinute.Value = 0;
}
if(nMinute.Value < 0)
{
nMinute.Value = 59;
}
tsTime = TimeSpan.Parse(nHour.ToString()+":"+nMinute.ToString()+":00");
}
What is the correct format for passing a time to tsTime TimeSpan object? I just have ":00" for the second since the user can only set the hours and the minutes. And, of course, since I do have a clock control that I made by creating my user control, the tsTime will be passed over to a string variable, so that, when the string variable has the same string as the clock's, the alarm label will show up.