forked from chunyi1994/cppevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
58 lines (44 loc) · 1.1 KB
/
timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef TIMER
#define TIMER
#include<sys/time.h>
#include<unistd.h>
#include<sys/time.h>
#include <string>
#include <ctime>
#include <cctype>
namespace cppevent{
typedef __time_t time_t;
class Time
{
public:
Time(const timeval& tv);
Time(time_t sec = 0, time_t usec = 0);
bool operator==(const Time& other) const;
bool operator>(const Time& other) const;
bool operator<(const Time& other) const; //有bug
Time& operator+(const Time& other);
time_t sec() const; //秒
time_t usec() const; //微秒 1秒= 10^6 毫秒
void setSec(time_t sec);
void setUSec(time_t usec);
void addSec(time_t sec);
void addUSec(time_t usec);
void add(const Time& other);
void now();
struct timeval& timeval();
private:
struct timeval tv_;
struct timezone tz_;
};
static std::string getTimeStr(){
std::time_t t;
std::time ( &t );
std::string tStr = std::ctime(&t);
//去掉回车
tStr.erase(tStr.size() - 1, 1);
return tStr;
}
}
//printf("tz_minuteswest:%d\n",tz.tz_minuteswest);
//printf("tz_dsttime:%d\n",tz.tz_dsttime);
#endif // TIMER