fastdo  0.6.8
time.hpp
浏览该文件的文档.
1 #ifndef __TIME_HPP__
2 #define __TIME_HPP__
3 //
4 // time 提供日期与时间相关的功能
5 //
6 
7 namespace winux
8 {
11 {
12 public:
13  struct Second
14  {
15  time_t value;
16  explicit Second( time_t second ) : value(second)
17  {
18  }
19  };
20  struct MilliSec
21  {
23  explicit MilliSec( uint64 millisec ) : value(millisec)
24  {
25  }
26  };
27 
29  DateTimeL();
31  DateTimeL( short year, short month, short day, short hour, short minute, short second, short millisec = 0 );
33  DateTimeL( Second const & utcSecond );
35  DateTimeL( MilliSec const & utcMillisec );
37  DateTimeL( String const & dateTimeStr );
38 
39  short getYear() const { return _year; }
40  short getMonth() const { return _month; }
41  short getDay() const { return _day; }
42  short getHour() const { return _hour; }
43  short getMinute() const { return _minute; }
44  short getSecond() const { return _second; }
45  short getMillisec() const { return _millisec; }
47  short getDayOfWeek() const { return _wday; }
49  short getDayOfYear() const { return _yday; }
50 
51  void setYear( short year ) { _year = year; }
52  void setMonth( short month ) { _month = month; }
53  void setDay( short day ) { _day = day; }
54  void setHour( short hour ) { _hour = hour; }
55  void setMinute( short minute ) { _minute = minute; }
56  void setSecond( short second ) { _second = second; }
57  void setMillisec( short millisec ) { _millisec = millisec; }
58 
59  time_t toUtcTime() const;
60  uint64 toUtcTimeMs() const;
61 
62  String toString() const;
64  DateTimeL & fromCurrent();
66  DateTimeL & fromTm( struct tm const * t );
67 
68  static ulong GetSecondsFromWeeks( int weeks ) { return weeks * 7UL * 86400UL; }
69  static ulong GetSecondsFromDays( int days ) { return days * 86400UL; }
70  static ulong GetSecondsFromHours( int hours ) { return hours * 3600UL; }
71  static ulong GetSecondsFromMinutes( int minutes ) { return minutes * 60; }
72 private:
73  short _millisec;
74  short _second;
75  short _minute;
76  short _hour;
77  short _day;
78  short _month;
79  short _year;
80  short _wday;
81  short _yday;
82 };
83 
84 WINUX_FUNC_DECL(std::ostream &) operator << ( std::ostream & o, DateTimeL const & dt );
85 
91 WINUX_FUNC_DECL(time_t) GetUtcTime( void );
92 
93 
94 
95 } // namespace winux
96 
97 #endif // __TIME_HPP__
static ulong GetSecondsFromDays(int days)
Definition: time.hpp:69
本地日期时间。L意思&#39;local&#39;,不包含时区信息
Definition: time.hpp:10
void setHour(short hour)
Definition: time.hpp:54
#define WINUX_DLL
Definition: utilities.hpp:60
void setMonth(short month)
Definition: time.hpp:52
XString< tchar > String
Definition: utilities.hpp:216
MilliSec(uint64 millisec)
Definition: time.hpp:23
short getDayOfYear() const
年第几日[1~366, 1=01-01]
Definition: time.hpp:49
void setDay(short day)
Definition: time.hpp:53
Second(time_t second)
Definition: time.hpp:16
static ulong GetSecondsFromMinutes(int minutes)
Definition: time.hpp:71
std::ostream & operator<<(std::ostream &o, ConsoleAttrT< _VarType > const &tr)
Definition: console.hpp:137
time_t GetUtcTime(void)
获取UTC时间秒数,或者调用CRT的time(NULL)
short getHour() const
Definition: time.hpp:42
void setSecond(short second)
Definition: time.hpp:56
static ulong GetSecondsFromHours(int hours)
Definition: time.hpp:70
#define WINUX_FUNC_DECL(ret)
Definition: utilities.hpp:64
short getSecond() const
Definition: time.hpp:44
static ulong GetSecondsFromWeeks(int weeks)
Definition: time.hpp:68
uint64 GetUtcTimeMs(void)
获取UTC时间毫秒数,UTC秒数可以直接除以1000,或者调用CRT的time(NULL)
short getMonth() const
Definition: time.hpp:40
short getYear() const
Definition: time.hpp:39
uint64 GetUtcTimeUs(void)
获取UTC时间微秒数,UTC秒数可以直接除以1000000,或者调用CRT的time(NULL)
short getMillisec() const
Definition: time.hpp:45
short getDayOfWeek() const
星期几[0~6, 0=Sunday]
Definition: time.hpp:47
void setMillisec(short millisec)
Definition: time.hpp:57
unsigned long ulong
Definition: utilities.hpp:171
void setMinute(short minute)
Definition: time.hpp:55
unsigned __int64 uint64
Definition: utilities.hpp:185
short getMinute() const
Definition: time.hpp:43
short getDay() const
Definition: time.hpp:41
跨平台基础功能库
Definition: archives.hpp:7
void setYear(short year)
Definition: time.hpp:51