title: Printing current time in milliseconds or nanoseconds with printf builtin
body: <p>We can print the current time with the builtin <code>printf</code> function, without needing to invoke an external command like <code>date</code>, like this:</p>
  
  <pre><code>printf '%(%Y-%m-%d:%H:%M:%S)T %s\n' -1
  # sample output: 2019-03-30:17:39:36,846
  </code></pre>
  
  <p>How can we make printf to print milliseconds or nanoseconds as well? Using <code>%3N</code> or <code>%N</code> in the format string doesn't work:</p>
  
  <pre><code>printf '%(%Y-%m-%d:%H:%M:%S,%3N)T %s\n' -1 # outputs 2019-03-30:17:38:16,%3N
  printf '%(%Y-%m-%d:%H:%M:%S,%N)T %s\n' -1  # outputs 2019-03-30:17:38:16,%N
  </code></pre>
  
  <p>However, the date command works fine:</p>
  
  <pre><code>date +%Y-%m-%d:%H:%M:%S,%3N # gives 2019-03-30:17:39:36,846
  date +%Y-%m-%d:%H:%M:%S,%N  # gives 2019-03-30:17:39:36,160643077
  </code></pre>
  
  <p>This is on a Red Hat Linux version 7.3.</p>