DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   REg: timestamp with milliseconds linux c++ (http://www.daniweb.com/forums/thread136661.html)

kriscbe Jul 25th, 2008 5:33 am
REg: timestamp with milliseconds linux c++
 
hi all,

i want to generate a timestamp with year,date,month,day,hours,min,seconds,milliseconds.
in my code i generated a time integer with the help of time().
with that integer can i generate timestamp with milliseconds.

sample code:

int len;  
        time_t mytime;
        presentTimeStamp = 1999999950;//this value is return from time()
        mytime = presentTimeStamp;
        struct tm *mytm; 
        mytm=localtime(&mytime); 
 
            strftime(timeArray,50,"%a, %d %b %Y %H:%M:%S",mytm);


//for milli seconds
        char timearray[20];
        int ms = mytime % 1000;
        sprintf(timearray, ":%03d", ms);
   
      //        printf("%s\n",timearray); 
        strcat(timeArray,timearray);
is it right??(i mean milli seconds calculation)


i am using linux(fc6)



thanks
kriscbe

ArkM Jul 25th, 2008 6:43 am
Re: REg: timestamp with milliseconds linux c++
 
1. Try http://www.meangene.com/notes/time.html
2. As usually, time_t returned from time(...) is in seconds, not milliseconds.
3. Use code and /code tags to present your codes.

Salem Jul 25th, 2008 12:54 pm
Re: REg: timestamp with milliseconds linux c++
 
Try gettimeofday()


All times are GMT -4. The time now is 4:45 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC