I'm trying to use the date
command to output today's date in the format %d.%m.%y-%H:%M:%S
. Obviously I just do that like this:
date +%d.%m.%y-%H:%M:%S
This works fine in bash and I get the output I'd expect, but when I do this in zsh I get what I'd expect prefixed by '7m', for example
7m07.09.12-16:49:37
instead of
07.09.12-16:49:37
I also get an alert from my terminal. This is caused by the %S
for seconds, because when I take that off the end of the command I don't get the '7m' (but obviously I'm missing the seconds off the end of the date).
Can anyone explain why this happens?
EDIT: extra information: I'm on OS X 10.8 and with zsh 4.3.11, oh-my-zsh installed
To format date in DD-MM-YYYY format, use the command date +%d-%m-%Y or printf "%(%d-%m-%Y)T\n" $EPOCHSECONDS .
date +%S. Displays seconds [00-59] date +%N. Displays in Nanoseconds.
The another way to enable timestamps in history output in zsh shell is to use fc command. The fc command, short for fix commands, is a shell built-in command used to list, edit and re-execute the most recently entered commands in to an interactive shell.
One workaround is to wrap the code around echo $(...)
. It produces the right output and was acceptable for me. Your original command would look like:
echo $(date +%d.%m.%y-%H:%M:%S)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With