Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - TimeSpan doesn't work with seconds for more than one day
    primarykey
    data
    text
    <p>I think the title of this question isn't good, but I couldn't find a better one.</p> <p>What I'm trying to do is to give users the ability to set a count-down timer. ( Look at picture No.1 ): <img src="https://i.stack.imgur.com/JXENE.png" alt="enter image description here"></p> <p>The application takes the user input and checks which time unit did the user select, then converts it into seconds and assign the value to an <strong>int</strong> variable.</p> <pre><code>private int seconds = -1; private void enable_button_Click(object sender, EventArgs e) { int amount = Convert.ToInt32(time_numericUpDown.Value); string unit = tUnits_comboBox.Text; // Check what time is chosen then convert it to seconds if (unit == "Seconds") seconds = amount; else if (unit == "Minutes") seconds = amount * 60; else if (unit == "Hours") seconds = amount * 3600; else if (unit == "Days") seconds = amount * 86400; // Clock it! timer.Enabled = true; } </code></pre> <hr> <p>Then, the timer should show the time in a human-readable format, I use this code for that:</p> <pre><code>private void timer_Tick(object sender, EventArgs e) { // Verify if the time didn't pass if (seconds == 0) { // If the time is over, do the specified action timer.Enabled = false; operation(); // &lt;&lt; This is the function that does the Action! } else { // Continue counting seconds -= 1; TimeSpan timeSpan = TimeSpan.FromSeconds(seconds); string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); status_label.Text = "Restarting in " + answer; } } </code></pre> <p>This works perfectly when the value of the "seconds" variable represents one day or less, but when it's more than 24 hours it just shows 24 hours in the status. What am I doing wrong?</p> <p>( The problem ):</p> <p><img src="https://i.stack.imgur.com/YaURD.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload