Author |
Message |
BugZap Guest
Offline
|
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Mon Aug 13, 2007 9:03 pm Post subject: |
 |
|
|
|
This is something I've reused from Catid -
String botInfo::RunningTime2(unsigned int start_time, unsigned int end_time)
{
String gt;
uint flagGameTime = end_time- start_time;
gt = getString(flagGameTime / 3600, 10, 2, true);
gt += "h ";
gt += getString((flagGameTime / 60) % 60, 10, 2, true);
gt += "m ";
gt += getString(flagGameTime % 60, 10, 2, true);
gt += "s";
return gt;
}
|
_________________ Performance is often the art of cheating carefully. - James Gosling |
|
Back to top |
|
 |
BugZap Guest
Offline
|
Posted: Mon Aug 13, 2007 10:18 pm Post subject: |
 |
|
|
|
Thanks for the quick reply CypherJF, It worked perfectly!!
BugZap |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Mon Aug 13, 2007 11:43 pm Post subject: |
 |
|
|
|
I tried to implement this for hyperspace racing using ctime but it wanted to do everything from the Unix epoch or something and came out weird, so it's not as pretty:
#define TIMEBUFFERSIZE 12
char *timeString(long time, char *buffer)
{
int minutes;
int seconds;
int millis;
minutes = (time - (time % 60000)) / 60000;
seconds = ((time - (minutes * 60000)) - ((time - (minutes * 60000)) % 1000)) / 1000;
millis = (time - (minutes * 60000) - (seconds * 1000));
snprintf(buffer, TIMEBUFFERSIZE-1, "%01d:%02d.%03d", minutes, seconds, millis);
buffer[TIMEBUFFERSIZE-1] = 0;
return buffer;
} |
usage is something like this (not tested)
char formatted[TIMEBUFFERSIZE];
long time = 60000; //1 minute
timeString(time, formatted);
printf("Time: %s" + formatted); |
ok gurus, time to tell me how this could be done better (I think the return is only still in there for legacy code) _________________
 |
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
|
Back to top |
|
 |
BugZap Guest
Offline
|
Posted: Tue Aug 14, 2007 3:45 am Post subject: |
 |
|
|
|
I just wish I could switch a integer to string and back more easily in C.
In JS you can just toString() a number or even more lame like someinteger+="" and its now a string..
Anyway, Thanks again that code from Catid also makes it easy to trim unneeded digits, so that 3:47 isnt displayed 03:47 etc. |
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Tue Aug 14, 2007 6:09 am Post subject: |
 |
|
|
|
Use Java, it can be compared to Javascript in code syntax (although both are completely different).  _________________
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Aug 14, 2007 10:20 am Post subject: |
 |
|
|
|
BugZap wrote: | I just wish I could switch a integer to string and back more easily in C. |
Because C/C++ actually let you know how expensive an operation is. If it's hard for you, it's probably hard for the computer.  _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
BugZap Guest
Offline
|
Posted: Tue Aug 14, 2007 2:35 pm Post subject: |
 |
|
|
|
String s = (String)minutes, I frogot about that... lol |
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Tue Aug 14, 2007 5:12 pm Post subject: |
 |
|
|
|
BugZap wrote: | Thanks for the quick reply CypherJF, It worked perfectly!!
BugZap |
Your welcome, it's only because I've had to use that code a few times before, and the external HD which has all my source code is plugged in right now.  |
|
Back to top |
|
 |
|