Append this to your ~/.zshrc file.
function preexec() {
timer=$(($(date +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000))
elapsed=$(($now-$timer))
export RPROMPT="%F{cyan}${elapsed}ms %{$reset_color%}"
unset timer
fi
}
Remixed from @adri's snippet.
Why not simply use the following?
cmd_start=$(print -P %D{%s%3.})
No need to ask for microsecs and then divide by 1000, if you can get millisecs directly...