CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: time function

  1. #1
    Join Date
    Apr 2007
    Posts
    21

    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;

  2. #2
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    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 ) );
    }

  3. #3
    Join Date
    Apr 2007
    Posts
    21

    Re: time function

    any help following my format above?

  4. #4
    Join Date
    Oct 2003
    Location
    Minnesota
    Posts
    175

    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.

  5. #5
    Join Date
    May 2005
    Posts
    4,954

    Re: time function

    Quote 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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)