시간연산


작성자 : CalmMass
작성일자 : 2010.05.28
제목 : 함수를 이용한 윈도우(windows) 시간 계산 방법
툴 : MS Visual C++ 6.0, STLPort 5.6, SDK
함 수 정리
GetLocalTime : IpSystemTime (현재 로컬 시간을 대입받을 SYSTEMTIME 구조체 사용합니다.) ( 바로가기 )
GetTickCount : 수행 시간을 측정 할때 많이 사용하는 함수( 바로가기 )
GetSystemTime : 현재 Windows System상의 날짜 및 시간을 반환 하는 함수( 바로가기 )
MFC
CTime : MFC에서 사용하는 시간 관련 클래스 단, Millisecond는 없다. ( 바로가기 )
CTime::CurrentTime() : 현재 시간을 구하기
CTimeSpan : MFC에서 사용하는 시간을 연산하는 방법이다. ( 바로가기 )

그외
---------------------------------------------------------------------------------------------
CompareFileTime
DosDateTimeToFileTime
FileTimeToDosDateTime
FileTimeToLocalFileTime
FileTimeToSystemTime
GetFileTime
GetLocalTime
GetSystemTime
GetSystemTimeAdjustment
GetSystemTimeAsFileTime
GetTickCount
GetTimeZoneInformation
LocalFileTimeToFileTime
SetFileTime
SetLocalTime
SetSystemTime
SetSystemTimeAdjustment
SetTimeZoneInformation
SystemTimeToFileTime
SystemTimeToTzSpecificLocalTime
---------------------------------------------------------------------------------------------

  • 시간을 연산하는 것이 말처럼 쉬운 것은 아니라고 생각 합니다. 밀리세컨드를 계산할때는 더욱 골치가 아프고 어떻게 연산을 해야 정확한 값을 가지고 오는지 여러번 테스트를 해야 합니다.
  • 가장 좋은 방법은 API를 활용하여 하나의 프로그램을 만드는 것도 좋지만 기존에 있는 좋은 라이브러리는 적절하게 사용하면 되겠습니다.
  • 그외 시간 관련 함수는 찾아

사용 방법 1. CTime

class CTime
{
public:

// Constructors
static CTime PASCAL GetCurrentTime();

CTime();
CTime(time_t time);
CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
int nDST = -1);
CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
CTime(const CTime& timeSrc);

CTime(const SYSTEMTIME& sysTime, int nDST = -1);
CTime(const FILETIME& fileTime, int nDST = -1);
const CTime& operator=(const CTime& timeSrc);
const CTime& operator=(time_t t);

// Attributes
struct tm* GetGmtTm(struct tm* ptm = NULL) const;
struct tm* GetLocalTm(struct tm* ptm = NULL) const;
BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;

time_t GetTime() const;
int GetYear() const;
int GetMonth() const; // month of year (1 = Jan)
int GetDay() const; // day of month
int GetHour() const;
int GetMinute() const;
int GetSecond() const;
int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat

// Operations
// time math
CTimeSpan operator-(CTime time) const;
CTime operator-(CTimeSpan timeSpan) const;
CTime operator+(CTimeSpan timeSpan) const;
const CTime& operator+=(CTimeSpan timeSpan);
const CTime& operator-=(CTimeSpan timeSpan);
BOOL operator==(CTime time) const;
BOOL operator!=(CTime time) const;
BOOL operator<(CTime time) const;
BOOL operator>(CTime time) const;
BOOL operator<=(CTime time) const;
BOOL operator>=(CTime time) const;

// formatting using "C" strftime
CString Format(LPCTSTR pFormat) const;
CString FormatGmt(LPCTSTR pFormat) const;
CString Format(UINT nFormatID) const;
CString FormatGmt(UINT nFormatID) const;

#ifdef _UNICODE
// for compatibility with MFC 3.x
CString Format(LPCSTR pFormat) const;
CString FormatGmt(LPCSTR pFormat) const;
#endif

// serialization
#ifdef _DEBUG
friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, CTime time);
#endif
friend CArchive& AFXAPI operator<<(CArchive& ar, CTime time);
friend CArchive& AFXAPI operator>>(CArchive& ar, CTime& rtime);

private:
time_t m_time;
};




사용 방법 2. CTimeSpan

class CTimeSpan
{
public:

// Constructors
CTimeSpan();
CTimeSpan(time_t time);
CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);

CTimeSpan(const CTimeSpan& timeSpanSrc);
const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);

// Attributes
// extract parts
LONG GetDays() const; // total # of days
LONG GetTotalHours() const;
int GetHours() const;
LONG GetTotalMinutes() const;
int GetMinutes() const;
LONG GetTotalSeconds() const;
int GetSeconds() const;

// Operations
// time math
CTimeSpan operator-(CTimeSpan timeSpan) const;
CTimeSpan operator+(CTimeSpan timeSpan) const;
const CTimeSpan& operator+=(CTimeSpan timeSpan);
const CTimeSpan& operator-=(CTimeSpan timeSpan);
BOOL operator==(CTimeSpan timeSpan) const;
BOOL operator!=(CTimeSpan timeSpan) const;
BOOL operator<(CTimeSpan timeSpan) const;
BOOL operator>(CTimeSpan timeSpan) const;
BOOL operator<=(CTimeSpan timeSpan) const;
BOOL operator>=(CTimeSpan timeSpan) const;

#ifdef _UNICODE
// for compatibility with MFC 3.x
CString Format(LPCSTR pFormat) const;
#endif
CString Format(LPCTSTR pFormat) const;
CString Format(UINT nID) const;

// serialization
#ifdef _DEBUG
friend CDumpContext& AFXAPI operator<<(CDumpContext& dc,CTimeSpan timeSpan);
#endif
friend CArchive& AFXAPI operator<<(CArchive& ar, CTimeSpan timeSpan);
friend CArchive& AFXAPI operator>>(CArchive& ar, CTimeSpan& rtimeSpan);

private:
time_t m_timeSpan;
friend class CTime;
};




사용 방법 3. MFC CTime 클래스 사용


CString CurrentTimeText;
CTime CurTime;

CurTime = CTime::GetCurrentTime(); // 현재 시스템 시각을 구한다.

CurrentTimeText.Format( "현재 날짜 / 시각 : %04d-%02d-%02d / %02d:%02d:%02d",
, CurTime.GetYear()
, CurTime.GetMonth()
, CurTime.GetDay()
, CurTime.GetHour()
, CurTime.GetMinute()
, CurTime.GetSecond()
);



  • 출처 : http://kongmks.cafe24.com/239?TSSESSION=7329c8d8597d2af44015e2b666bb2e6f
  • CString 문자열 클래스에 현재 시간을 대입하여 Format로 각각의 년/월/요 시/분/초 로 정의 할 수 있습니다.

사용 방법 4. Millisecond(밀리세컨드) 현재 시간

SYSTEMTIME cur_time;
GetLocalTime(&cur_time);
CString strPCTime;


strPCTime.Format("%04d%02d%02d%02d%02d%02d%03ld",
cur_time.wYear,
cur_time.wMonth,
cur_time.wDay,
cur_time.wHour,
cur_time.wMinute,
cur_time.wSecond,
cur_time.wMilliseconds); );



  • 출처 : http://blog.naver.com/sanglyn/90047509460
  • CTime 클래스에 밀리세컨드가 없기 때문에 GetLocalTime() API 함수를 이용하여 밀리세컨드 값을 구합니다.


사용 방법 5. GetTickCount 활용 방법

SYSTEMTIME cur_time;

어떤 명령어의 수행시간을 측정하고 싶을때가 있다.
이때 유용하게 사용할수 있는 함수가 GetTickCount()이다.

GetTickCount()함수는 시스템이 시작 된 후 얼마의 시간이 경과했는지를 반환한다. 단위는 밀리세컨드 단위이다. 참고로 경과시간은 DWORD(32비트 값)이므로 최대 49.7일이 지나면 다시 0으로 된다고 한다.

The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. To obtain the system timer resolution, use the GetSystemTimeAdjustment function.

DWORD GetTickCount(void);

Parameters : This function has no parameters.
Return values : The return value is the number of milliseconds that have elapsed since the system was started.


#include
#include //GetTickCount()함수 이용을 위해 추가한다.

using namespace std;

void main()
{
long startTime = GetTickCount(); //현재 시각을 저장한다.(시작지점)

for(int i=0; i<100000; i++) //시간 딜레이를 주기 위해 i값을 출력한다.
cout<<

long endTime = GetTickCount(); //현재 시각을 저장한다.(종료지점)
long tickDiff = endTime - startTime; //수행시간 = 종료시각 - 시작시각
long secDiff = tickDiff / 1000 ; //이건 초단위로도 나타내기 위한 것.

cout<<"Start Time : "<<<"ms"<
cout<<"End Time : "<<<"ms"<
cout<<"Tick difference : "<<<"ms"<
cout<<"Second difference : "<<<"s"<
}



  • 출처 : http://dolbbi.com/83
  • 수행시간을 측정하는 방법이며 이것은 49.7일 지나면 0으로 반환 됩니다.

출처 : http://calmmass.tistory.com/220

Posted by rCan

2010/06/21 14:30 2010/06/21 14:30
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/598

미니마이즈

::ShowWindow(m_hParent, SW_MINIMIZE);

Posted by rCan

2010/06/18 18:57 2010/06/18 18:57
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/597

무서운 꿈

저녁 10시쯤 자리에 누웠다.
잠이 오지 않아서 티비를 켜서 티비를 보다가 갑자기 졸음이 몰려와 티비를 끄고
잠을 청했다.

그러고 몇 분후 누군가 내 팔을 잡아 당겼다.
아프게 당긴것도 살살 당긴것도 잠을 살짝 깨울정도로 팔을 당겼다.
눈을뜨자 마자. 아 가위구나 하는 생각에 가위를 풀려고 노력을 해보았다.
누군가 당기는 손의 반대편 손은 자유롭게 움직일 수가 있었다.
그렇다면 가위는 풀린것같은데 아직도 한쪽팔을 누군가가 당기고 있다.

너무 무서워서 당겨지는 반대손으로 당기는 손을 내 몸쪽으로 끌어 당기려고 하자
몸전체를 누르는 듯한 힘을 느꼇다.
아.. 이번엔 이중 가위인건가 하면서 내 가위를 풀려고 노력했다.

노력이라고 해봤자 손을 움직여서 가위를 풀려고 했지만 노력은 허사가 되었다.
누군가가 내 옆에 누워있는 느낌을 받았다.

심각한 가위라 생각하고 어떻게든 풀려고 노력했다.
10분 15분 시간이 지났을 무렵 가위는 풀렸다.
그리고 그 공포심에 아악! 하고 소리를 지르며 몸을 움직였다.

집전체는 고요했다. 아무도 내 소리를 못들은 것 처럼.
전에는 이런 일이 없었기에 너무나도 무서워서
어머니가 주무시는 마루로 나가서 옆에 누웠다.
어머니는 살짝 깨셔서 왜 그러냐고 물으셧다.
나는 그냥 무서워서 나왔다고 했다.

그리고 잠시후 또 눈을 감았다.

그러자 이번에는 이불속에서 누군가가 있다... 이불속에서 나를 노려보고 있다.
이불속을 차마 볼 수 없었다.
하체를 덮고 있던 이불은 점점 부풀어 났다.
마치 짐승이라도 들어온 것처럼 점점 더 커져 갔다.
잠시후 그것은 나의 하체를 밀기 시작했다.

점점 점점..

점점 더 거칠게

밀기 시작했다.

나의 하체는 그 통증을 느끼기 시작했다.
그가 누르면 누를수록 밀면 밀수록 더욱더 통증은 고통은 더욱 커져만 갔다.

결국 내 몸은 그 힘을 이기지 못하고 벽쪽으로 쭈욱 밀려갔다.
벽과 만나는 동시에 아악 하고 소리질러보았지만 목소리는 나오지 않았다.
분명 벽과 부디쳤을꺼라고 생각은 했지만 내 몸은 벽과 만나지 않고
그대로 그벽을 통과하여 아무것도 보이지 않은 어두운 곳으로 밀려갔다.

그리고 몇분후 나는 소리를 지르며 내가 자던 방에서 깨어났다.

Posted by rCan

2010/05/06 09:58 2010/05/06 09:58
Response
No Trackback , a comment
RSS :
http://rcan.net/rss/response/596

« Previous : 1 : 2 : 3 : 4 : 5 : 6 : ... 144 : Next »

블로그 이미지

- rCan

Calendar

«   2010/09   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

Notices

  1. About Me

Recent Posts

Site Stats

Total hits:
89710
Today:
20
Yesterday:
42