date Command in Linux: Format, Timezone, and Epoch

By 

Updated on

6 min read

Linux Date Command Examples

The date command displays or sets the system date and time. It is most commonly used to print the date in different formats, convert timezones, and work with Unix timestamps. This article explains how to use the date command and covers the most useful formatting options and examples.

Using the Linux date Command

The syntax for the date command is as follows:

txt
date [OPTION]... [+FORMAT]

To display the current system time and date using the default formatting, invoke the command without any options and arguments:

Terminal
date

The output includes the day of the week, month, day of the month, time, timezone, and year:

output
Sat Jun  1 14:31:01 CEST 2019

Date Formatting Options

The output of the date command can be formatted with a sequence of format control characters preceded by a + sign. The format controls start with the % symbol and are substituted by their values.

Terminal
date +"Year: %Y, Month: %m, Day: %d"

The %Y character will be replaced with the year, %m with month and %d with the day of the month:

output
Year: 2019, Month: 06, Day: 02

Here is another example:

Terminal
date "+DATE: %D%nTIME: %T"
output
DATE: 06/02/19
TIME: 01:47:04

Here are some of the most common formatting characters:

  • %a — Locale’s abbreviated weekday name (e.g., Mon)
  • %A — Locale’s full weekday name (e.g., Monday)
  • %b — Locale’s abbreviated month name (e.g., Jan)
  • %B — Locale’s full month name (e.g., January)
  • %d — Day of month (e.g., 01)
  • %D — Date in mm/dd/yy format (e.g., 06/01/19)
  • %F — Date in YYYY-MM-DD format (e.g., 2019-06-01)
  • %H — Hour in 24-hour format (00..23)
  • %I — Hour in 12-hour format (01..12)
  • %j — Day of year (001..366)
  • %m — Month (01..12)
  • %M — Minute (00..59)
  • %S — Second (00..60)
  • %s — Unix timestamp (seconds since epoch)
  • %T — Time in HH:MM:SS format
  • %u — Day of week (1..7), Monday is 1
  • %Y — Full four-digit year (e.g., 2019)
  • %z — Timezone offset from UTC (e.g., +0100)
  • %Z — Timezone abbreviation (e.g., CEST)

To get a full list of all formatting options run date --help or man date in your terminal.

Date String

The -d option allows you to operate on a specific date. You can specify the date as a human-readable date string like below:

Terminal
date -d "2010-02-07 12:10:53"
output
Sun Feb  7 12:10:53 CET 2010

Using the custom formatting:

Terminal
date -d '16 Dec 1974' +'%A, %d %B %Y'
output
Monday, 16 December 1974

The date string accepts values such as “tomorrow”, “friday”, “last friday”, “next friday”, “next month”, and “next week”.

Terminal
date -d "last week"
output
Sat May 25 14:31:42 CEST 2019

You can also use the date string option to show the local time for different timezones. For example, to show the local time for 6:30AM next Monday on the Australian east coast, you would type:

Terminal
date -d 'TZ="Australia/Sydney" 06:30 next Monday'
output
Sun Jun  2 22:30:00 CEST 2019

Override the Timezone

The date command returns the date in the default system timezone . To use a different timezone set the environment variable TZ to the desired timezone.

For example, to show the time in Melbourne, Australia, you would type:

Terminal
TZ='Australia/Melbourne' date
output
Sat Jun  1 22:35:10 AEST 2019

To list all available time zones , you can either list the files in the /usr/share/zoneinfo directory or use the timedatectl list-timezones command.

You can also include the timezone offset or abbreviation directly in the formatted output using %z and %Z:

Terminal
date +"%Y-%m-%d %H:%M:%S %Z (%z)"
output
2019-06-01 14:35:10 CEST (+0100)

Display UTC Time

To display the current time in UTC rather than the local timezone, use the -u flag:

Terminal
date -u
output
Sat Jun  1 12:35:10 UTC 2019

To format UTC output, combine -u with a format string:

Terminal
date -u +"%Y-%m-%d %H:%M:%S UTC"
output
2019-06-01 12:35:10 UTC

Epoch Converter

The date command can be used as an Epoch converter. Epoch, or Unix timestamps, is the number of seconds that have elapsed since January 1, 1970 at 00:00:00 UTC.

To print the number of seconds since the Unix epoch, invoke date with the %s format control:

Terminal
date +%s
output
1559393792

To convert seconds since the epoch to date, set the seconds as a date string prefixed with @:

Terminal
date -d @1234567890
output
Sat Feb 14 00:31:30 CET 2009

Using date with Other Commands

The date command is most frequently used to create filenames that contain the current time and date.

The command below will create a MySQL backup file in the following format database_name-20190601.sql:

Terminal
mysqldump database_name > database_name-$(date +%Y%m%d).sql

You can also use the date command in your shell scripts. In the example below we are assigning the output of date to the date_now variable:

sh
date_now=$(date "+%F-%H-%M-%S")

echo $date_now
output
2019-06-01-15-02-27

Display the Last Modification Time of a File

The date command with the -r option shows the last modification time of a file. For example:

Terminal
date -r /etc/hosts
output
Tue Jul 24 11:11:48 CEST 2018

If you want to modify the file timestamp, use the touch command .

Set the System Time and Date

Setting the system time and date manually with the date command is not recommended because on most Linux distributions, the system clock is synchronized using chrony, ntp, or systemd-timesyncd.

However, if you want to set the system clock manually, you can use the --set= option.

Changing the system clock affects running services, logs, and scheduled jobs, and it typically requires root privileges. For example, if you want to set the date and time to 5:30pm, June 01, 2019, you would type:

Terminal
date --set="20190601 17:30"

Quick Reference

CommandDescription
dateCurrent date and time (default format)
date +%FDate in YYYY-MM-DD format
date +%TTime in HH:MM:SS format
date +"%F %T"Date and time combined
date -uCurrent UTC time
date +%sUnix timestamp
date -d @TIMESTAMPConvert Unix timestamp to date
date -d "tomorrow"Tomorrow’s date
date -d "last monday"Last Monday’s date
TZ=Zone dateDate in a specific timezone
date -r FILELast modification time of a file
date --set="DATE"Set the system date and time

FAQ

What is the simplest way to get the date in YYYY-MM-DD format?
Use date +%F. This is a shorthand for %Y-%m-%d and outputs the date as 2019-06-01.

How do I display the current UTC time?
Run date -u to print the current time in UTC. To format it, use date -u +"%Y-%m-%d %H:%M:%S".

How do I get the current Unix timestamp?
Use date +%s. This prints the number of seconds since January 1, 1970 at 00:00:00 UTC.

What is the difference between %Z and %z?
%Z prints the timezone abbreviation (e.g., CEST), while %z prints the numeric UTC offset (e.g., +0100).

Can I use date to calculate a date in the future or past?
Yes. Use the -d option with a natural language string: date -d "30 days" for 30 days from now, or date -d "last monday" for the previous Monday.

Conclusion

The Linux date command is a flexible tool for displaying, formatting, and converting dates and times. Combine it with shell scripts or command substitution to create timestamps, rotate log files, or schedule time-sensitive operations.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page