REg: timestamp with milliseconds linux c++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 1
Reputation: kriscbe is an unknown quantity at this point 
Solved Threads: 0
kriscbe kriscbe is offline Offline
Newbie Poster

REg: timestamp with milliseconds linux c++

 
0
  #1
Jul 25th, 2008
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:

  1. int len;
  2. time_t mytime;
  3. presentTimeStamp = 1999999950;//this value is return from time()
  4. mytime = presentTimeStamp;
  5. struct tm *mytm;
  6. mytm=localtime(&mytime);
  7.  
  8. strftime(timeArray,50,"%a, %d %b %Y %H:%M:%S",mytm);
  9.  
  10.  
  11. //for milli seconds
  12. char timearray[20];
  13. int ms = mytime % 1000;
  14. sprintf(timearray, ":%03d", ms);
  15.  
  16. // printf("%s\n",timearray);
  17. strcat(timeArray,timearray);
is it right??(i mean milli seconds calculation)


i am using linux(fc6)



thanks
kriscbe
Last edited by Tekmaven; Jul 25th, 2008 at 2:04 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: REg: timestamp with milliseconds linux c++

 
0
  #2
Jul 25th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: REg: timestamp with milliseconds linux c++

 
0
  #3
Jul 25th, 2008
Try gettimeofday()
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC