简体   繁体   中英

Need help creating a 24 minute day clock

I need help with some code that i am writing for a small text rpg. Its basically a clock that simulates a day, which will be 24 minutes instead of 24 hours. 1 second will equal one minute, and 1 minute will equal one hour. The clock will start from 12:00 and go to 12:00. I need ideas on how to write this code. This is code that i have come

time_t rawtime;
 int hours;
 int minutes;
 int seconds;

 struct tm * timeinfo;

 time ( &rawtime );
 timeinfo = localtime ( &rawtime );

 if(timeinfo->tm_hour > 12)
  timeinfo->tm_hour = timeinfo->tm_hour - 12;

 hours = timeinfo->tm_hour;
 minutes = timeinfo->tm_min;
 seconds = timeinfo->tm_sec;

Just get the current time, convert to seconds, then multiply by sixty. Finally, convert back.

Example:

myrealtime_s = hours*60*60+minutes*60+seconds;
myfaketime_s = myrealtime_s*60;

myfaketime_seconds = myfaketime_s % 60;
myfaketime_minutes = (myfaketime_s/60) % 60;
myfaketime_hours = (myfaketime_s/(60*60)) % 24;

myfaketime_extraseconds = myfaketime_s-(myfaketime_hours*60*60+myfaketime_minutes*60+myfaketime_seconds);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM