time.cpp 671 Bytes
Newer Older
Matteo's avatar
update  
Matteo committed
1
2
#include "time.h"

Matteo's avatar
update    
Matteo committed
3
std::string getTimeLabel(int ms, std::string delim) {
Matteo's avatar
update  
Matteo committed
4
5
6
7
8
9
10

	int mil = ms % 1000;
	int sec = ms / 1000;
	int min = (sec / 60) % 60;
	int hours = sec / 3600;
	sec = sec % 60;

Matteo's avatar
update    
Matteo committed
11
	std::string hoursStr = std::to_string(hours), minStr = std::to_string(min), secStr = std::to_string(sec), milStr = std::to_string(mil);
Matteo's avatar
update  
Matteo committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	if (hours < 10)
		hoursStr = "0" + hoursStr;
	if (min < 10)
		minStr = "0" + minStr;
	if (sec < 10)
		secStr = "0" + secStr;
	if (mil < 100) {
		if (mil < 10) {
			milStr = "00" + milStr;
		} else {
			milStr = "0" + milStr;
		}
	}

Matteo's avatar
update    
Matteo committed
26
    std::string timeLabel = hoursStr + delim + minStr + delim + secStr + delim + milStr;
Matteo's avatar
update  
Matteo committed
27
28
29

	return timeLabel;
}