date Command in Linux: Format, Timezone, and Epoch

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:
date [OPTION]... [+FORMAT]To display the current system time and date using the default formatting, invoke the command without any options and arguments:
dateThe output includes the day of the week, month, day of the month, time, timezone, and year:
Sat Jun 1 14:31:01 CEST 2019Date 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.
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:
Year: 2019, Month: 06, Day: 02Here is another example:
date "+DATE: %D%nTIME: %T"DATE: 06/02/19
TIME: 01:47:04Here 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:
date -d "2010-02-07 12:10:53"Sun Feb 7 12:10:53 CET 2010Using the custom formatting:
date -d '16 Dec 1974' +'%A, %d %B %Y'Monday, 16 December 1974The date string accepts values such as “tomorrow”, “friday”, “last friday”, “next friday”, “next month”, and “next week”.
date -d "last week"Sat May 25 14:31:42 CEST 2019You 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:
date -d 'TZ="Australia/Sydney" 06:30 next Monday'Sun Jun 2 22:30:00 CEST 2019Override 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:
TZ='Australia/Melbourne' dateSat Jun 1 22:35:10 AEST 2019To 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:
date +"%Y-%m-%d %H:%M:%S %Z (%z)"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:
date -uSat Jun 1 12:35:10 UTC 2019To format UTC output, combine -u with a format string:
date -u +"%Y-%m-%d %H:%M:%S UTC"2019-06-01 12:35:10 UTCEpoch 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:
date +%s1559393792To convert seconds since the epoch to date, set the seconds as a date string prefixed with @:
date -d @1234567890Sat Feb 14 00:31:30 CET 2009Using 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:
mysqldump database_name > database_name-$(date +%Y%m%d).sqlYou 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:
date_now=$(date "+%F-%H-%M-%S")
echo $date_now2019-06-01-15-02-27Display the Last Modification Time of a File
The date command with the -r option shows the last modification time of a file. For example:
date -r /etc/hostsTue Jul 24 11:11:48 CEST 2018If 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:
date --set="20190601 17:30"Quick Reference
| Command | Description |
|---|---|
date | Current date and time (default format) |
date +%F | Date in YYYY-MM-DD format |
date +%T | Time in HH:MM:SS format |
date +"%F %T" | Date and time combined |
date -u | Current UTC time |
date +%s | Unix timestamp |
date -d @TIMESTAMP | Convert Unix timestamp to date |
date -d "tomorrow" | Tomorrow’s date |
date -d "last monday" | Last Monday’s date |
TZ=Zone date | Date in a specific timezone |
date -r FILE | Last 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.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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