I need to get a date in a specific format but can't work out how to do it.
Here is how I'm getting the date at the moment.
date -r "$timestamp" +'%Y-%m-%dT%H:%M:%S.s'
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.
Any idea how I can do such a thing?
Current Workaround
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.
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"`