⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hightimer.cpp

📁 linux程序
💻 CPP
字号:
#include <stdio.h>
#include "HighTimer.h"

HighTimer::HighTimer()
{
    mIsError = gettimeofday(&cTm,&cTmz);
}

HighTimer::~HighTimer()
{
	
}

HighTimer::HighTimer(HighTimer &t1)
{
	// mIsError = gettimeofday(&cTm,&cTmz);
	cTm.tv_sec  = t1.cTm.tv_sec;
	cTm.tv_usec = t1.cTm.tv_usec;
	cTmz.tz_minuteswest = t1.cTmz.tz_minuteswest;
	cTmz.tz_dsttime     = t1.cTmz.tz_dsttime;
}

HighTimer::HighTimer(struct timeval t1)
{
	mIsError = gettimeofday(&cTm,&cTmz);
	cTm.tv_sec  = t1.tv_sec;
	cTm.tv_usec = t1.tv_usec;
}

/*
	Timer::Timer(time_t tm)
	{
		mCurrTime = tm;
		mLocalTime = *localtime(&mCurrTime);

	}
*/

HighTimer::HighTimer(UInt16 year,UInt16 month,UInt16 mday,UInt16 hour,UInt16 minute,UInt16 second,UInt32 millseconds)
{
	time_t curTime;
	struct tm curLocalTime;
	//if(year < 1900)
	if(year < 1900)
        return;

	mIsError = gettimeofday(&cTm,&cTmz);
	// curLocalTime.tm_year  = year - 1900;
	curLocalTime.tm_year  = year - 1900;
	curLocalTime.tm_mon   = month - 1;
	curLocalTime.tm_mday  = mday;
	curLocalTime.tm_hour  = hour;
	curLocalTime.tm_min   = minute;
	curLocalTime.tm_sec   = second;
	curTime = mktime(&curLocalTime);
	cTm.tv_sec  = curTime;
	cTm.tv_usec = millseconds * 1000;


	
}
	
void HighTimer::GetTimer(HighTimer *tm)
{
	
}
		
UInt16 HighTimer::GetYear()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_year + 1900;

}

UInt16 HighTimer::GetMonth()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_mon + 1;
	
}

UInt16 HighTimer::GetDayOfMonth()
{
	struct tm mLocalTime = * localtime(&cTm.tv_sec);
	return mLocalTime.tm_mday;
}

UInt16 HighTimer::GetDayOfWeek()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_wday;

	
}

UInt16 HighTimer::GetDayOfYear()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_yday;
}

UInt16 HighTimer::GetHour()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_hour;
	
}

UInt16 HighTimer::GetMinute()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_min;

	
}

UInt16 HighTimer::GetSecond()
{
	struct tm mLocalTime = *localtime(&cTm.tv_sec);
	return mLocalTime.tm_sec;
}

UInt32 HighTimer::GetMicroSeond()
{
	return cTm.tv_usec/1000;
	
}

Bool8 HighTimer::SetSystemTimer()
{
	int result = settimeofday(&cTm,&cTmz);
	if(result == 0)
		return true;
	else
		return false;
}

void HighTimer::DisplayMe()
{
	printf("CurrentTimer: %04d-%02d-%02d %02d:%02d:%02d\n",GetYear(),GetMonth(),GetDayOfMonth(),GetHour(),GetMinute(),GetSecond());
	printf("%d,%d \n",cTmz.tz_minuteswest,cTmz.tz_dsttime); 
	printf("CurrentTimer %d(second),%d(microsecond) \n",cTm.tv_sec,cTm.tv_usec);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -