입력한 틱 타임값을 날짜 구조체에 담는다.
/*
// 날짜 관련 구조체. operator 포함
struct SDate
{
int iYear;
int iMonth;
int iDay;
int iHour;
int iMin;
int iSec;
SDate()
{
Initialize();
}
void Initialize()
{
memset( this, 0x00, sizeof(SDate) );
}
SDate& operator=( const SDate& rhsDate )
{
this->iYear = rhsDate.iYear;
this->iMonth = rhsDate.iMonth;
this->iDay = rhsDate.iDay;
this->iHour = rhsDate.iHour;
this->iMin = rhsDate.iMin;
this->iSec = rhsDate.iSec;
return (*this);
}
bool operator<( const SDate& rhsDate ) const
{
if( this->iYear > rhsDate.iYear ) return false;
if( this->iYear < rhsDate.iYear ) return true;
if( this->iMonth > rhsDate.iMonth ) return false;
if( this->iMonth < rhsDate.iMonth ) return true;
if( this->iDay > rhsDate.iDay ) return false;
if( this->iDay < rhsDate.iDay ) return true;
if( this->iHour > rhsDate.iHour ) return false;
if( this->iHour < rhsDate.iHour ) return true;
if( this->iMin > rhsDate.iMin ) return false;
if( this->iMin < rhsDate.iMin ) return true;
if( this->iSec >= rhsDate.iSec ) return false;
return true;
}
bool operator>( const SDate& rhsDate ) const
{
if( this->iYear < rhsDate.iYear ) return false;
if( this->iYear > rhsDate.iYear ) return true;
if( this->iMonth < rhsDate.iMonth ) return false;
if( this->iMonth > rhsDate.iMonth ) return true;
if( this->iDay < rhsDate.iDay ) return false;
if( this->iDay > rhsDate.iDay ) return true;
if( this->iHour < rhsDate.iHour ) return false
if( this->iHour > rhsDate.iHour ) return true;
if( this->iMin < rhsDate.iMin ) return false;
if( this->iMin > rhsDate.iMin ) return true;
if( this->iSec <= rhsDate.iSec ) return false;
return true;
}
bool operator==( const SDate& rhsDate ) const
{
if( this->iYear != rhsDate.iYear ) return false;
if( this->iMonth != rhsDate.iMonth ) return false;
if( this->iDay != rhsDate.iDay ) return false;
if( this->iHour != rhsDate.iHour ) return false;
if( this->iMin != rhsDate.iMin ) return false;
if( this->iSec != rhsDate.iSec ) return false;
return true;
}
bool operator!=( const SDate& rhsDate ) const
{
if( this->iYear != rhsDate.iYear ) return true;
if( this->iMonth != rhsDate.iMonth ) return true;
if( this->iDay != rhsDate.iDay ) return true;
if( this->iHour != rhsDate.iHour ) return true;
if( this->iMin != rhsDate.iMin ) return true;
if( this->iSec != rhsDate.iSec ) return true;
return false;
}
bool operator<=( const SDate& rhsDate ) const
{
if( this->iYear > rhsDate.iYear ) return false;
if( this->iYear < rhsDate.iYear ) return true;
if( this->iMonth > rhsDate.iMonth ) return false;
if( this->iMonth < rhsDate.iMonth ) return true;
if( this->iDay > rhsDate.iDay ) return false;
if( this->iDay < rhsDate.iDay ) return true;
if( this->iHour > rhsDate.iHour ) return false;
if( this->iHour < rhsDate.iHour ) return true;
if( this->iMin > rhsDate.iMin ) return false;
if( this->iMin < rhsDate.iMin ) return true;
if( this->iSec > rhsDate.iSec ) return false;
return true;
}
bool operator>=( const SDate& rhsDate ) const
{
if( this->iYear < rhsDate.iYear ) return false;
if( this->iYear > rhsDate.iYear ) return true;
if( this->iMonth < rhsDate.iMonth ) return false;
if( this->iMonth > rhsDate.iMonth ) return true;
if( this->iDay < rhsDate.iDay ) return false;
if( this->iDay > rhsDate.iDay ) return true;
if( this->iHour < rhsDate.iHour ) return false;
if( this->iHour > rhsDate.iHour ) return true;
if( this->iMin < rhsDate.iMin ) return false;
if( this->iMin > rhsDate.iMin ) return true;
if( this->iSec < rhsDate.iSec ) return false;
return true;
}
} // !SDate
*/
// 입력한 Tick 값을 Date 구조체에 담는다.
void GetTimeToDateInfo( SDate& sDateInfo, int iTime )
{
//time_t atm = time( NULL ); // 현재 시간 초 단위로 담기
time_t atm = static_cast<time_t>( iTime );
tm tmTime;
// 현재 초단위 시간을 분리하여 구조체 담기
// 2번째 인자에 Tick을 넣으면 그 Tick 시간 설정된 시간으로 구조체 담기
// localtime 함수로 현재 시간 구할 수 있으나 VS 2005 이후보안이 강화
// localtime 사용시 waring c4996 경고 뜸
localtime_s( &tmTime, &atm );
sDateInfo.iSec = tmTime.tm_sec;
sDateInfo.iMin = tmTime.tm_min;
sDateInfo.iHour = tmTime.tm_hour;
sDateInfo.iDay = tmTime.tm_mday;
sDateInfo.iMonth = tmTime.tm_mon + 1;
sDateInfo.iYear = tmTime.tm_year + 1900;
}
'[ Programing ] > Algorithm' 카테고리의 다른 글
설정된 기간 관련 카운터(주간) 계산하기 (0) | 2014.01.10 |
---|---|
SYSTEMTIME 시간 차이 TickTime -> Day 계산. mktime, difftime (0) | 2013.12.20 |
OS(운영체제) 이름 알아오기 (0) | 2013.11.14 |
VARIANT 해제 (0) | 2013.05.21 |
길찾기 알고리즘 링크 (0) | 2013.05.21 |