- Home /
Checking How Many Minutes Have Passed This Day?
Morning folks, wondering if I could get a little general C# help, just trying to figure out how I could record the total minutes past in the current real day. I can work out how to call the current minute in the hour from the system time, but I'm not sure how I would calculate the whole day so far.
GUI.Label (new Rect(90,90,200,90), System.DateTime.Now.TimeOfDay.Minutes.ToString());
Thats my method of getting the current minutes in a label, but I can't figure out how to record the whole day so far. If anyone can give me hints it would be appreciated :)
Answer by aldonaletto · Sep 19, 2011 at 12:24 AM
I think you just have to change System.DateTime.Now.TimeOfDay.Seconds.ToString() to System.DateTime.Now.TimeOfDay.Minutes.ToString() - according to this doc, TimeOfDay represents the time elapsed since midnight, and can be read as minutes as well (it's a TimeSpan structure).
EDITED: Well, a brute force approach would be to calculate this using hours and minutes:
DateTime now = System.DateTime.Now; int mins = now.Hour*60+now.Minute; GUI.Label(..., mins.ToString());NOTE: I'm a JS guy, thus the code above may have some rubbish!
Whups I pasted the wrong version of the code, updating now. The problem still remains of how to calculate the whole day in $$anonymous$$utes so far since midnight. Thank you for the thoughts regardless though :)
But isn't this returning the $$anonymous$$utes passed since midnight?
Nope, just the $$anonymous$$utes past since the turn of the hour :(
I edited the answer to calculate the $$anonymous$$utes using Hour and $$anonymous$$inute from System.DateTime.Now
Wicked! That makes sense to me, I'm away from my desk for the next hour or so but will try it when I'm back and let you know :)
Your answer
Follow this Question
Related Questions
Conversion of seconds to hours and minutes 1 Answer
C# Check If Minutes equal some denomination of 5 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Instatiate object in every given second problem C# 2 Answers