2#include <helper/STime.h>
5static const int kMaxTimeBufferSize = 128;
19 m_timeSpan = nSecs + 60 * (nMins + 60 * (nHours + int64_t(24) * lDays));
24 return (m_timeSpan / (24 * 3600));
29 return (m_timeSpan / 3600);
39 return (m_timeSpan / 60);
64 return (
STimeSpan(m_timeSpan + span.m_timeSpan));
69 return (
STimeSpan(m_timeSpan - span.m_timeSpan));
74 m_timeSpan += span.m_timeSpan;
80 m_timeSpan -= span.m_timeSpan;
86 return (m_timeSpan == span.m_timeSpan);
91 return (m_timeSpan != span.m_timeSpan);
96 return (m_timeSpan < span.m_timeSpan);
101 return (m_timeSpan > span.m_timeSpan);
106 return (m_timeSpan <= span.m_timeSpan);
111 return (m_timeSpan >= span.m_timeSpan);
116STime::STime(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
int nDST)
118 SetDateTime(nYear, nMonth, nDay, nHour, nMin, nSec);
129 atm.tm_mon = nMonth - 1;
130 atm.tm_year = nYear - 1900;
133 m_time = _mktime64(&atm);
144 SASSERT(ptm != NULL);
148 struct tm *tmTemp = localtime(&m_time);
172 timeDest.wYear = (WORD)(1900 + ptm->tm_year);
173 timeDest.wMonth = (WORD)(1 + ptm->tm_mon);
174 timeDest.wDayOfWeek = (WORD)ptm->tm_wday;
175 timeDest.wDay = (WORD)ptm->tm_mday;
176 timeDest.wHour = (WORD)ptm->tm_hour;
177 timeDest.wMinute = (WORD)ptm->tm_min;
178 timeDest.wSecond = (WORD)ptm->tm_sec;
179 timeDest.wMilliseconds = 0;
186 return (
STime(::_time64(NULL)));
195 memset(¤t, 0,
sizeof(current));
197 current.tm_year = st.wYear - 1900;
198 current.tm_mon = st.wMonth - 1;
199 current.tm_mday = st.wDay;
200 current.tm_hour = st.wHour;
201 current.tm_min = st.wMinute;
202 current.tm_sec = st.wSecond;
203 time_t currentTime = _mkgmtime(¤t);
204 return static_cast<uint64_t
>(currentTime) * 1000 + st.wMilliseconds;
214 struct tm *ptm = localtime(&m_time);
215 return ptm ? (ptm->tm_year + 1900) : 0;
220 struct tm *ptm = localtime(&m_time);
221 return ptm ? (ptm->tm_mon + 1) : 0;
226 struct tm *ptm = localtime(&m_time);
227 return ptm ? ptm->tm_mday : 0;
232 struct tm *ptm = localtime(&m_time);
233 return ptm ? ptm->tm_hour : -1;
238 struct tm *ptm = localtime(&m_time);
239 return ptm ? ptm->tm_min : -1;
244 struct tm *ptm = localtime(&m_time);
245 return ptm ? ptm->tm_sec : -1;
250 struct tm *ptm = localtime(&m_time);
251 return ptm ? ptm->tm_wday + 1 : 0;
263 return (m_time == time.m_time);
268 return (m_time != time.m_time);
273 return (m_time < time.m_time);
278 return (m_time > time.m_time);
283 return (m_time <= time.m_time);
288 return (m_time >= time.m_time);
307 return (
STimeSpan(m_time - time.m_time));
322 if (pszFormat == NULL)
327 TCHAR szBuffer[kMaxTimeBufferSize];
329 struct tm *tmTemp = localtime(&m_time);
330 if (tmTemp || !_tcsftime(szBuffer, kMaxTimeBufferSize, pszFormat, tmTemp))
int GetMinute() const
获取分钟
STime operator+(STimeSpan span) const
加法运算符重载
STime & operator-=(STimeSpan span)
减法赋值运算符重载
static STime GetCurrentTime()
获取当前时间
STimeSpan operator-(STime time) const
减法运算符重载
bool operator>(STime time) const
大于运算符重载
static uint64_t GetCurrentTimeMs()
获取当前时间的毫秒数
bool operator<=(STime time) const
小于等于运算符重载
STime & operator+=(STimeSpan span)
加法赋值运算符重载
bool GetAsSystemTime(SYSTEMTIME &timeDest) const
获取系统时间结构
bool operator>=(STime time) const
大于等于运算符重载
__time64_t GetTime() const
获取时间秒数
bool operator==(STime time) const
等于运算符重载
void SetDate(int nYear, int nMonth, int nDay)
设置日期
int GetDayOfWeek() const
获取星期几
SStringT Format(LPCTSTR pszFormat) const
格式化时间字符串
bool operator<(STime time) const
小于运算符重载
bool operator!=(STime time) const
不等于运算符重载
STime(__time64_t tm=0)
默认构造函数
void SetDateTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST=-1)
设置日期和时间
STime & operator=(__time64_t time)
赋值运算符重载
struct tm * GetLocalTm(struct tm *ptm) const
获取本地时间结构
bool operator!=(STimeSpan span) const
不等于运算符重载
LONGLONG GetTotalMinutes() const
获取总分钟数
LONGLONG GetDays() const
获取天数
LONG GetSeconds() const
获取秒数
bool operator<(STimeSpan span) const
小于运算符重载
LONGLONG GetTotalHours() const
获取总小时数
STimeSpan & operator-=(STimeSpan span)
减法赋值运算符重载
STimeSpan operator-(STimeSpan span) const
减法运算符重载
LONG GetMinutes() const
获取分钟数
bool operator>(STimeSpan span) const
大于运算符重载
bool operator==(STimeSpan span) const
等于运算符重载
LONG GetHours() const
获取小时数
bool operator>=(STimeSpan span) const
大于等于运算符重载
bool operator<=(STimeSpan span) const
小于等于运算符重载
STimeSpan operator+(STimeSpan span) const
加法运算符重载
__time64_t GetTimeSpan() const
获取时间间隔秒数
STimeSpan & operator+=(STimeSpan span)
加法赋值运算符重载
LONGLONG GetTotalSeconds() const
获取总秒数