This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to see the current Unix timestamp and other date formats on the command line

07 Mar 2009

The UNIX date command can show the current (or a future) date in several different formats. The command’s default output presents a full date string:

date

Sat Mar  7 07:25:51 SAST 2009

... but this output can be modified by specifying certain arguments.

To see the output in a different format:

date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"

DATE: 2009-03-07
TIME: 07:27:43

To see the last Friday of the month:

date -v1d -v+1m -v-1d -v-fri

Fri Mar 27 07:29:28 SAST 2009

To display the current UNIX Timestamp:

date +%s

1236403850

The date command has several other arguments which can be found by reviewing its man page:

man date
Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.