| | 55 | |
| | 56 | std::string FormatTime(box_time_t time, bool showMicros) |
| | 57 | { |
| | 58 | std::ostringstream buf; |
| | 59 | |
| | 60 | time_t seconds = BoxTimeToSeconds(time); |
| | 61 | int micros = BoxTimeToMicroSeconds(time) % MICRO_SEC_IN_SEC; |
| | 62 | |
| | 63 | struct tm tm_now, *tm_ptr = &tm_now; |
| | 64 | |
| | 65 | #ifdef WIN32 |
| | 66 | if ((tm_ptr = localtime(&seconds)) != NULL) |
| | 67 | #else |
| | 68 | if (localtime_r(&seconds, &tm_now) != NULL) |
| | 69 | #endif |
| | 70 | { |
| | 71 | buf << std::setfill('0') << |
| | 72 | std::setw(2) << tm_ptr->tm_hour << ":" << |
| | 73 | std::setw(2) << tm_ptr->tm_min << ":" << |
| | 74 | std::setw(2) << tm_ptr->tm_sec; |
| | 75 | |
| | 76 | if (showMicros) |
| | 77 | { |
| | 78 | buf << "." << std::setw(6) << micros; |
| | 79 | } |
| | 80 | } |
| | 81 | else |
| | 82 | { |
| | 83 | buf << strerror(errno); |
| | 84 | } |
| | 85 | |
| | 86 | return buf.str(); |
| | 87 | } |
| | 88 | |