📄 timer.cpp
字号:
#include "Timer.h"
namespace CTI_RDP_NAMESPACE
{
Timer::Timer()
{
time(&mCurrTime);
//struct tm *localTime = localtime(mCurrTime);
//memcpy(&mLocalTime,localTime,sizeof(mLocalTime));
mLocalTime = *localtime(&mCurrTime);
}
Timer::Timer(time_t tm)
{
mCurrTime = tm;
mLocalTime = *localtime(&mCurrTime);
}
Timer::Timer(Timer &tm)
{
mCurrTime = tm.GetTimer();
mLocalTime = *localtime(&mCurrTime);
}
Timer::Timer(UInt16 year,UInt16 month,UInt16 mday,UInt16 hour,UInt16 minute,UInt16 second)
{
if(year < 1900)
return;
mLocalTime.tm_year = year - 1900;
mLocalTime.tm_mon = month - 1;
mLocalTime.tm_mday = mday;
mLocalTime.tm_hour = hour;
mLocalTime.tm_min = minute;
mLocalTime.tm_sec = second;
mCurrTime = mktime(&mLocalTime);
}
Timer::~Timer()
{
}
void Timer::SetCurrentTime()
{
time(&mCurrTime);
mLocalTime = *localtime(&mCurrTime);
}
OS_Error Timer::GetLongTime(char *buf)
{
sprintf(buf,"[ %04d-%02d-%02d %02d:%02d:%02d ] ",GetYear(),GetMonth(),GetDayOfMonth(),GetHour(),GetMinute(),GetSecond());
return OS_NOERROR;
}
OS_Error Timer::GetLogTime(char *buf)
{
sprintf(buf,"%04d-%02d-%02d",GetYear(),GetMonth(),GetDayOfMonth());
return OS_NOERROR;
}
OS_Error Timer::GetTimeWithInterval(char *buf,char ch)
{
sprintf(buf,"[ %04d%c%02d%c%02d %02d%c%02d%c%02d ]",GetYear(),ch,GetMonth(),ch,GetDayOfMonth(),GetHour(),ch,GetMinute(),ch,GetSecond());
return OS_NOERROR;
}
SInt64 Timer::DiffTimer(Timer &time2)
{
SInt64 difference = (SInt64)difftime(GetTimer(),time2.GetTimer());
return difference;
}
UInt16 Timer::GetYear()
{
return mLocalTime.tm_year + 1900;
}
UInt16 Timer::GetMonth()
{
return mLocalTime.tm_mon + 1;
}
UInt16 Timer::GetDayOfMonth()
{
return mLocalTime.tm_mday;
}
UInt16 Timer::GetDayOfWeek()
{
return mLocalTime.tm_wday;
}
UInt16 Timer::GetDay()
{
return mLocalTime.tm_mday;
}
UInt16 Timer::GetDayOfYear()
{
return mLocalTime.tm_yday;
}
UInt16 Timer::GetHour()
{
return mLocalTime.tm_hour;
}
UInt16 Timer::GetMinute()
{
return mLocalTime.tm_min;
}
UInt16 Timer::GetSecond()
{
return mLocalTime.tm_sec;
}
SInt32 Timer::GetTimeInterval()
{
time_t curTime;
time(&curTime);
return (curTime - mCurrTime);
}
Timer& Timer::operator - (TimerSpan &t)
{
mCurrTime = mCurrTime - t.GetTimer();
mLocalTime = *localtime(&mCurrTime);
return (*this);
}
TimerSpan::TimerSpan()
{
mCurrTime = 0;
}
TimerSpan::TimerSpan(UInt32 day, UInt32 hour, UInt32 minute, UInt32 second)
{
mCurrTime = second + 60* (minute + 60* (hour + 24* day));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -