File: TimeUtils.cpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (20 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <sstream> 
#include <time.h>
#include <iomanip> // std::setfill setd::setw
#include "TimeUtils.hpp"

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();
}