time.cpp 752 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
Matteo committed
4
5
6
7
8
    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
9

Matteo's avatar
Matteo committed
10
11
12
13
14
15
16
17
18
19
20
21
    std::string hoursStr = std::to_string(hours), minStr = std::to_string(min), secStr = std::to_string(sec),
                milStr = std::to_string(mil);
    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
22

Matteo's avatar
update    
Matteo committed
23
    std::string timeLabel = hoursStr + delim + minStr + delim + secStr + delim + milStr;
Matteo's avatar
update  
Matteo committed
24

Matteo's avatar
Matteo committed
25
    return timeLabel;
Matteo's avatar
update  
Matteo committed
26
}