0

How to design an alarm?

Okay, not exactly an alarm. What I wish to do is for the user to enter a time (or, set the alarm), and then the program should display the time left till the alarm. So basically, the function should store the time entered by the user, then compare it with the current local time and then display the time remaining. PS. I tried it in C. But the answer can be in any language.

8th Nov 2019, 3:04 PM
Sarthak Dash
Sarthak Dash - avatar
5 Answers
+ 4
Sarthak Dash, I make a function in C#, I hope it can help. With the following function you can calculate the remaining time form a DateTime. I used the format: {YYYY, MM, DD, HH, MM, SS} because you will see the days, hours, minutes and seconds remaining (normally I don't think you will make a reminder for the next year but it's possible :P) public void RemainingTime(DateTime dateTimeReminder) { string time = null; //The format of the RemainingDateTime is: {YYYY, MM, DD, HH, MM, SS} DateTime dateTimeNow = DateTime.Now; TimeSpan timeSpan = dateTimeReminder - dateTimeNow; //If you want to display the difference of the months and years you can place another if statement that will counter the months and years. if (timeSpan.Days > 0) { time = timeSpan.Days + " days "; } time +=
quot;{timeSpan.Hours:00}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}"; //The remaining time will be shown in a MessageBox and is of the type String. MessageBox.Show(@"The remaining time is: " + time + @" left", @"Remaining Time left"); } You can call the function above with the following code: RemainingTime(new DateTime(2019, 12, 19, 16, 01, 00)); I hope this is what you are looking for :)
19th Nov 2019, 3:39 PM
Kevin Stevelmans
Kevin Stevelmans - avatar
0
Hi Sarthak, Do you actually want to know how to make a design like how to style the applkcation or do you want to know how to make it?
13th Nov 2019, 10:34 PM
Kevin Stevelmans
Kevin Stevelmans - avatar
0
Kevin Stevelmans, No. I just want to know the code. The designing and interface doesn't matter.
19th Nov 2019, 2:03 PM
Sarthak Dash
Sarthak Dash - avatar
0
Kevin Stevelmans, thanks a lot. This is what I was looking for.
19th Nov 2019, 3:43 PM
Sarthak Dash
Sarthak Dash - avatar
0
Great glad to hear :) Good luck!
19th Nov 2019, 3:47 PM
Kevin Stevelmans
Kevin Stevelmans - avatar