title: Get Formatted Date From Timestamp With Rounded Milliseconds Bash Shell Script
body: <p>I need to get a date in a specific format but can't work out how to do it.</p>
  
  <p>Here is how I'm getting the date at the moment.</p>
  
  <pre><code>date -r "$timestamp" +'%Y-%m-%dT%H:%M:%S.s'
  </code></pre>
  
  <p>However the issue is the milliseconds has too many digits for the format I need. I need the milliseconds to be limited to 3 digits.</p>
  
  <p>Any idea how I can do such a thing?</p>
  
  <p><strong>Current Workaround</strong></p>
  
  <p>Not accurate but it works. I calculate the milliseconds afterwards and then just take the first three characters of the string. Obviously this doesn't take into account round up.</p>
  
  <pre><code>date_string_one=`date -r "$timestamp" +'%Y-%m-%dT%H:%M:%S.'`
  date_string_milli=`date -r "$timestamp" +'%s'`
  date_string="$date_string_one"`printf "%.3s" "$date_string_milli"`
  </code></pre>