helpThe GNU Bourne-Again SHell - Support: sr #109599, Can we have nanosecond timestamps...


sr #109599: Can we have nanosecond timestamps in printf?

Submitter:  None
Submitted:  Fri 07 Dec 2018 08:41:48 AM UTC
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  Works For Me
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Thu 20 Dec 2018 04:52:59 PM UTC, comment #1: 

If the OS and its strftime(3) implementation support nanoseconds, you can access them using %(...)T.

Bash doesn't implement any of the time formats itself; it just passes them to strftime().

Chet Ramey <chet>
Project Administrator
Fri 07 Dec 2018 08:41:48 AM UTC, original submission:  

For being more accurate in timing things it would be nice to not have to start any external program and use the built in printf to access the timestamp in nanosecond accuracy (yeah, nano seconds is not really needed but you can always reduce from there, hard to get more accuracy later, and its already there).

Other shells seem to support %N for accessing the nanoseconds part of an internal clock_gettime (or similar) call. If the underlying OS doesn't have one that returns nanoseconds it seems to be appropriate to just scale up, a lot of OSs I have seen return nanoseconds but are really just internally using microseconds and multiply by 1000.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.





    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-20 chet StatusNone Works For Me

    Back to the top

    Powered by Savane 3.10