I have seen many examples for displaying time but I couldn't find any which was simple and easy to use. Anyone please guide me how to display system time in C++. I only want to display hours not the date nor time or seconds.
How to display system hour in c++
Page 1 of 12 Replies - 2426 Views - Last Post: 16 November 2010 - 03:32 AM
Replies To: How to display system hour in c++
#2
Re: How to display system hour in c++
Posted 16 November 2010 - 03:04 AM
Knowing the Operating System you are coding for would be helpful.
#3
Re: How to display system hour in c++
Posted 16 November 2010 - 03:32 AM
First:
"ctime Convert time_t value to string (function)"
Second:
"char * ctime ( const time_t * timer );
Convert time_t value to string
Converts the time_t object pointed by timer to a C string containing a human-readable version of the corresponding local time and date.
The returned string has the following format:
Www Mmm dd hh:mm:ss yyyy
"
Thus:
"ctime Convert time_t value to string (function)"
Second:
"char * ctime ( const time_t * timer );
Convert time_t value to string
Converts the time_t object pointed by timer to a C string containing a human-readable version of the corresponding local time and date.
The returned string has the following format:
Www Mmm dd hh:mm:ss yyyy
"
Thus:
#include <time.h> time_t rawtime; time(&rawtime); //rawtime now holds the time in string formated as above. //since you want hours (pos 8 and 9), and strings can be used //just like arrays: char hours[2]; hours[0]=rawtime[8]; hours[1]=rawtime[9]; cout<<hours;
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote







|