SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
TimeUtil.hh
Go to the documentation of this file.
1 #ifndef SLIC_TIMEUTIL_HH
2 #define SLIC_TIMEUTIL_HH 1
3 
4 // std
5 #include <ctime>
6 #include <cstdio>
7 #include <iostream>
8 #include <string>
9 
10 namespace slic {
11 
16 class TimeUtil {
17 
18  public:
19 
20  typedef long long long64;
21 
22  static std::string getAscTime() {
23  tm* timeinfo = get_tm_local();
24 
25  std::string s = asctime(timeinfo);
26  s.erase(s.end() - 1, s.end());
27  return s;
28  }
29 
31  static long64 getTimeNS() {
32  long64 t_sec = (long64) time(NULL);
33  long64 t_ns = t_sec * ((long64) 1e9);
34  return t_ns;
35  }
36 
37  static std::string getDate() {
38  tm* timeinfo = get_tm_local();
39  char buffer[11];
40  strftime(buffer, 11, "%Y-%m-%d", timeinfo);
41  return std::string(buffer);
42  }
43 
44  static tm* get_tm_local() {
45  time_t rawtime;
46  struct tm* timeinfo;
47 
48  time(&rawtime);
49  timeinfo = localtime(&rawtime);
50 
51  return timeinfo;
52  }
53 };
54 
55 } // namespace slic
56 
57 #endif
Miscellaneous time-related utilities.
Definition: TimeUtil.hh:16
static std::string getDate()
Definition: TimeUtil.hh:37
static tm * get_tm_local()
Definition: TimeUtil.hh:44
static long64 getTimeNS()
Definition: TimeUtil.hh:31
static std::string getAscTime()
Definition: TimeUtil.hh:22
long long long64
Definition: TimeUtil.hh:20
@ time
Definition: LogStream.hh:26