time.h ctime and milliseconds

This is a discussion on time.h ctime and milliseconds within the C Programming forums, part of the General Programming Boards category; Hi Guys, I am trying to access the system time using th eheader file time.h and then using ctime(). This ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    1

    time.h ctime and milliseconds

    Hi Guys,

    I am trying to access the system time using th eheader file time.h and then using ctime(). This is great for the system date and time in seconds and works ok. But I want the time in milliseconds. Does anyone know how to do this or where I am going wrong.

    This is my code:

    Code:
    #include <time.h>
    
    #include <stdio.h>
    
     
    
     
    
    int main(void)
    
    {
    
       time_t lt;
    
     
    
       
    
       char c;
    
       while(c !='z')
    
       {
    
       lt=time(NULL);
    
     
    
        printf(ctime(&lt));
    
     
    
     
    
       printf("\nPress Any key to Continue");
    
       while((c=getchar()) != '\n')
    
       {
    
       printf("/n still not equal");
    
       }
    
        }
    
     
    
     
    
       return(0);
    
     
    
    }
    Thanks

    Andy.

  2. #2
    -AppearingOnThis..........
    Join Date
    May 2005
    Location
    Netherlands
    Posts
    44
    I think you can use the gettimeofday() function or GetSystemTime() if you're on a windows system.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    If you have DJGPP you can type "time" and right-click on it to search the help for "time". I think you might also try utime() or something (DJGPP specific).

    Why do you want to know the millisecond?

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    1
    On a POSIX system, see:

    clock_t clock()

    which returns the number of microseconds since the process was started. (Not milliseconds)

    On Win32, see:
    DWORD GetTickCount()

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    Try reading Forum rule number 5
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21