Military time variable

Posted By: Truth

Military time variable - 04/08/14 19:57

Hi, I use military time format for my game but I need to display it on a panel in time format.

For example the variable is 1600 for 4 o clock and displays in a panel as 1600 but I need to separate the hour from the minute and put a colon in between like this 16:00. I managed to get the hour by dividing the variable by 100 example 'time_day / 100 = hour' but how can I get the minute?

Thanks
Posted By: Uhrwerk

Re: Military time variable - 04/08/14 20:02

The variables are called sys_hours and sys_minutes.
Posted By: Truth

Re: Military time variable - 04/08/14 20:08

Thanks for reply but I'm not using the system time. Im using my own in game time which is using the variable 'time_day'. is there a way to display half a variable? I.e for 1249 just '12' in one panel and just '49' in another?
Posted By: Dico

Re: Military time variable - 04/08/14 20:29

use window for that
Posted By: WretchedSid

Re: Military time variable - 04/08/14 21:12

Code:
float time = 1652 / 100.0;

int hours = (int)time;
int minutes = (time - hours) * 100;



hours is 16, minutes is 52.
Also, you are doing time calculation and storage wrong. What you really want is a variable that accumulates time in the smallest unit that you want to store and then calculate the time of day from there.


Also, Dico, I like your way of opening doors with tanks. All kidding aside, how are you going to take care of things like kerning with that?
Posted By: Dico

Re: Military time variable - 04/08/14 21:51

JustSid : laugh

i'm not have much time to help in this forum , but from time to time i open forum page and see the news and all what i found is questions grin
Posted By: Truth

Re: Military time variable - 04/08/14 22:04

Thanks for the replies I overcame the problem by using the time_day / 100
example time_day = 1652; hour = time_day / 10, 16.52 is the new variable and I display that on a panel and cover the decimal with another panel containing ':'



But JustSid this is the exact calculation I was looking for to give me the minutes! Thanks laugh
© 2024 lite-C Forums