Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date command with zsh

Tags:

date

zsh

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

like image 297
stonesam92 Avatar asked Sep 07 '12 15:09

stonesam92


People also ask

How do you display 2 days back date in dd mm yyyy format in Linux?

To format date in DD-MM-YYYY format, use the command date +%d-%m-%Y or printf "%(%d-%m-%Y)T\n" $EPOCHSECONDS .

What is date +% s in bash?

date +%S. Displays seconds [00-59] date +%N. Displays in Nanoseconds.

How do I add timestamp to zsh history?

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.


1 Answers

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)
like image 82
Lycha Avatar answered Oct 31 '22 07:10

Lycha