Thread: printing time in HH:MM:SS:MS format

  1. #1
    Registered User
    Join Date
    May 2007

    Post printing time in HH:MM:SS:MS format

    hi all,

    i want to print time in HH:MM:SS:MS<millisec> format... how to do??

    Thanks in advance....

    Last edited by msenthil; 10-24-2007 at 01:02 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Where are you reading time from, and in what format?

    Apart from milliseconds, I would use time.h and strftime().
    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.

  3. #3
    Registered User
    Join Date
    May 2007
    using date command im reading time.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Well then look at the date man page. Something like this
    date '+&#37;H:%M:%S'
    gives you HH:MM:SS. I don't see an option for milliseconds.

    Why are you using the date command, anyway? It's not very portable, and depending on how you are executing it, probably slow.

    Consider using some functions from time.h. There are also unportable Linux functions that return milliseconds, but I can't recall their names at the moment.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Printing the data in the right format
    By c_geek in forum C Programming
    Replies: 48
    Last Post: 12-24-2007, 04:19 PM
  3. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 07:17 AM
  4. How to read in time format?
    By witchiz brews in forum C Programming
    Replies: 1
    Last Post: 02-12-2006, 02:10 AM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM