File: TimeUtils.cpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,020 kB
  • sloc: cpp: 77,250; python: 331; sh: 103; makefile: 41
file content (20 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <pbdata/utils/TimeUtils.hpp>

#include <ctime>
#include <iomanip>  // std::setfill setd::setw
#include <sstream>

std::string GetTimestamp()
{
    time_t timer;
    time(&timer);  // t is an integer type
    // Prepare timestamp in the format : 2012-04-05T09:26:02.689093
    std::stringstream timeStrm;
    struct tm t;
    localtime_r(&timer, &t);
    timeStrm << t.tm_year + 1900 << "-" << std::setfill('0') << std::setw(2) << t.tm_mon + 1 << "-"
             << std::setfill('0') << std::setw(2) << t.tm_mday << "T" << std::setfill('0')
             << std::setw(2) << t.tm_hour << ":" << std::setfill('0') << std::setw(2) << t.tm_min
             << ":" << std::setfill('0') << std::setw(2) << t.tm_sec;
    return timeStrm.str();
}