how to read system time in c++

Status
Not open for further replies.

ehsanelahimirza

Full Member level 6
Joined
Feb 24, 2006
Messages
334
Helped
28
Reputation
56
Reaction score
7
Trophy points
1,298
Activity points
3,570
how to read system time in c

hi all

plz tell me how to read system time as

hour
minutes
seconds
AM/PM

in c++

what variables will store these values
plz if give algo + any working example( compiler visual c)
 

sztime c++

hi ehsanelahimirza!

Use CTime an MFC class.

CTime ct = CTime::GetCurrentTime();

int minute = ct.GetMinute();
int hour = ct.GetHour();
int seconds=ct.GetSecond();


An Microsoft examples:

void CMainFrame::OnUpdateTime(CCmdUI *pCmdUI)
{
CTime t = CTime::GetCurrentTime();
char szTime[6];
int nHour = t.GetHour();
int nMinute = t.GetMinute();

// Base Hours on 12 instead of 24
if (nHour > 12)
nHour = nHour - 12;

wsprintf(szTime, "%i:%02i", nHour, nMinute);

// Now set the text of the pane.
m_wndStatusBar.SetPaneText(
m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),
LPCSTR(szTime));
pCmdUI->Enable();
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…