|
-
April 25th, 2007, 02:44 PM
#1
time function
Im supposed to make a function that prints the current time in the format like: 11:20:23 pm.
Here is what I got so far. Any hints would be helpful...
Code:
void printTime()
{
time t*clock_p = newtime_t;
time_t clock;
int seconds, minutes, hours;
int T;
clock = time(clock_p)
T = (int)clock;
// lost on rest...
return;
-
April 25th, 2007, 02:49 PM
#2
Re: time function
Found this on MSDN:
Code:
// crt_asctime.c
#include <time.h>
#include <stdio.h>
struct tm *newtime;
time_t aclock;
int main( void )
{
time( &aclock ); // Get time in seconds
newtime = localtime( &aclock ); // Convert time to struct tm form
/* Print local time as a string */
printf( "Current date and time: %s", asctime( newtime ) );
}
-
April 25th, 2007, 02:54 PM
#3
Re: time function
any help following my format above?
-
April 25th, 2007, 02:57 PM
#4
Re: time function
Take a look here: http://msdn2.microsoft.com/en-us/lib...1b(VS.71).aspx
Remarks:
The asctime function converts a time stored as a structure to a character string. The timeptr value is usually obtained from a call to gmtime or localtime, which both return a pointer to a tm structure, defined in TIME.H.
-
April 25th, 2007, 04:22 PM
#5
Re: time function
 Originally Posted by Action12
Im supposed to make a function that prints the current time in the format like: 11:20:23 pm.
Here is what I got so far. Any hints would be helpful...
Code:
void printTime()
{
time t*clock_p = newtime_t;
time_t clock;
int seconds, minutes, hours;
int T;
clock = time(clock_p)
T = (int)clock;
// lost on rest...
return;
What about using COleDateTime :
Code:
COleDateTime time = COleDateTime::GetCurrentTime();
CString szMyTime = time.Format(VAR_TIMEVALUEONLY);
?
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|