- Home /
How much seconds exist until midnight?
Hi,
I need an int which has value of how many seconds will exist until midnight. I am using time = System.DateTime.Compare(System.DateTime.Now, //today midnight dont know how to write);
Then I want var time convert to int seconds
Thanks
Comment
Best Answer
Answer by SmileQ · Nov 16, 2015 at 10:48 AM
DateTime current = DateTime.Now; // current time
DateTime tomorrow = current.AddDays(1).Date; // this is the "next" midnight
double secondsUntilMidnight = (tomorrow - current ).TotalSeconds; // get the difference between the DateTimes and get seconds
This should do the trick. Convert it to int if you want.