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 :slight_smile:

1 Answer

1

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 minutes so far since midnight. Thank you for the thoughts regardless though :)

But isn't this returning the minutes passed since midnight?

Nope, just the minutes past since the turn of the hour :(

I edited the answer to calculate the minutes using Hour and Minute 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 :)