1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef _BASE_TIME_H_
- #define _BASE_TIME_H_
- #include <time.h>
- #include <stdint.h>
- #include <string>
- #include "utils/TimeHelper.h"
- #include "utils/Log.h"
- namespace base {
- const int Hour = 60 * 60;
- const int Day = Hour * 24;
- class DateTime {
- public:
- DateTime();
- DateTime(time_t timestamp);
- DateTime(const std::string& datetimestr);
- std::string ToString();
- int64_t Unix() const;
- bool after(const DateTime& t) const {
- return true;
- }
- bool before(const DateTime& t) const {
- return true;
- }
- DateTime Add(int64_t seconds);
- public:
- int year = 0;
- int month = 0;
- int day = 0;
- int hour = 0;
- int min = 0;
- int second = 0;
- int week = 0; /* 星期–取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
- };
- /**
- * 开机累计毫秒数
- * @return
- */
- int64_t uptime();
- /**
- * 获得当前日期时间
- * @return
- */
- class DateTime GetDateTimeNow();
- /**
- * 设置系统日期时间
- * @param timestamp
- */
- void SetSystemDateTime(time_t timestamp);
- /**
- * 设置系统日期时间
- * @param dt
- */
- void SetSystemDateTime(const DateTime& dt);
- //设置时区 - 东八区
- inline void SetTimeZone() {
- setenv("TZ", "CST-8", 1);
- }
- } /* namespace base */
- #endif /* _FY_TIME_H_ */
|