Code: Show/Hide function convetToTime() { var _time = 391/60; var _roundtime = Math.round(100*_time)/100; var _outputtime = _roundtime.toString().replace(".", ":"); alert(_time + " : " + _roundtime + " : " + _outputtime); } |
Code: Show/Hide 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; } |
Code: Show/Hide #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; } |
Code: Show/Hide char formatted[TIMEBUFFERSIZE];
long time = 60000; //1 minute timeString(time, formatted); printf("Time: %s" + formatted); |
Code: Show/Hide int millis;
int seconds; int minutes; millis = time % 1000; time /= 1000; seconds = time % 60; minutes = time / 60; ... |
Code: Show/Hide String timestring(long time) { int millis = time % 1000; time /= 1000; int seconds = time % 60; int minutes = time / 60; String s = (String)minutes + ":" + (String)seconds; return s; } |
BugZap wrote: |
I just wish I could switch a integer to string and back more easily in C. |
BugZap wrote: |
Thanks for the quick reply CypherJF, It worked perfectly!!
BugZap |