Linux date Command Generator

Pick a target date and get the exact commands to set your system clock, format output, or do date math in the terminal.

Set System Date

pick a date and time, get the commands

Format Output

build a date +FORMAT command
Uses the same format codes as strftime. The + prefix is required.
Command
date "+%Y-%m-%d %H:%M:%S"
Preview
-

Date Math

relative date calculations in Bash
Command
date -d "+1 day" "+%Y-%m-%d %H:%M:%S"
Preview
-

Set Timezone

pick a timezone, get the command

Quick Reference

The Linux date command generator builds the exact terminal commands you need to set your system clock, format the current date for a script, calculate a relative date, or change the timezone. Pick a target date and platform (GNU/Linux, macOS, or FreeBSD) and the tool generates copy-ready commands using the correct flags and syntax for each operating system.

Why the date Command Differs Between Operating Systems

The date command exists on virtually every Unix-like system, but the flags and syntax are different on each one. GNU coreutils (used on most Linux distributions) accepts free-form expressions like date -d "+1 day". macOS and FreeBSD ship the BSD version of date, which uses a structured offset syntax like date -v+1d instead. Using a Linux command on macOS or vice versa produces cryptic errors, so this generator outputs the correct version for the platform you select.

What This Tool Generates

The generator covers the four most common reasons to reach for the date command in a terminal:

When to Use Each Command

Setting the system clock manually is rare on modern hosts because NTP keeps the time accurate automatically. The most common reasons you would override that are reproducing a bug that depends on a specific date, testing a license expiry path, or recovering a virtual machine whose clock has drifted out of sync. Always stop NTP first (sudo systemctl stop systemd-timesyncd) or your manual change will be overwritten within seconds.

Formatting dates with date +FORMAT is the daily-driver use case. Shell scripts, cron jobs, log filenames, and backup paths all need a consistent date string. Common patterns: date +%Y-%m-%d for an ISO date, date +%s for the current Unix timestamp, and date +%Y%m%d_%H%M%S for a sortable filename suffix. You can decode an existing Unix timestamp the other direction with the main timestamp converter.

Date math (relative date calculations) is how shell scripts pick a backup retention window, set a cookie expiry, or skip the last N days of logs. The GNU -d flag accepts natural-language expressions because the underlying parser is very permissive. The BSD -v flag is stricter but produces the same result with a flag-per-unit syntax. If you need to schedule a recurring command instead of calculating a single date, the cron builder generates the schedule expression.

Frequently Asked Questions

On modern systemd-based distributions the preferred command is timedatectl set-time "YYYY-MM-DD HH:MM:SS". The legacy command date -s "YYYY-MM-DD HH:MM:SS" still works on most systems. Run sudo hwclock --systohc afterward so the change persists across reboots. The generator outputs all three commands so you can pick the one your system supports.

macOS ships the BSD version of date, which has different flags from the GNU version used on Linux. Where GNU uses -d "+1 day", BSD uses -v+1d. The generator outputs the correct syntax when you select macOS or FreeBSD in the platform switcher. If you prefer GNU syntax on macOS, install coreutils via Homebrew and use gdate instead.

Run date +%s to print the current Unix timestamp in seconds. For milliseconds use date +%s%3N (GNU only, since BSD date does not support nanoseconds). The +%s format works identically on Linux, macOS, and FreeBSD, making it the most portable way to get a timestamp in a shell script.

On GNU/Linux use date -d "+7 days" or date -d "yesterday" with any natural-language expression. On macOS and FreeBSD use date -v+7d or date -v-1d with the BSD flag syntax. The generator outputs the correct syntax for the platform you choose and shows a live preview of the calculated date below the command.

The portable command is sudo timedatectl set-timezone Region/City (for example Europe/Berlin). On older non-systemd distributions, the equivalent is to symlink /etc/localtime to the matching zoneinfo file. Verify the change with timedatectl status or date. The generator outputs both the change and the verification command together.

NTP is correcting your manual change automatically. Almost every modern host runs a time-sync daemon (systemd-timesyncd, chronyd, or ntpd) that resets the clock from a network time server. Stop the daemon first with sudo systemctl stop systemd-timesyncd before setting the time manually, then restart it when you are done.

date -s is the legacy way to set the clock and changes only the system (software) time, leaving the hardware clock untouched until the next reboot. timedatectl set-time is the modern systemd interface that updates both the system clock and tells the kernel about the change, so it is the recommended choice on any systemd-based distribution.

The format codes are the same strftime tokens used in C, Python, PHP, and most other languages. %Y is the four-digit year, %m the two-digit month, %d the day, %H the hour, %M the minute, %S the second, and %s the Unix timestamp. The strftime builder tool on this site lets you assemble a format string visually and see the result update live.

Commands that only read the date (date, date +FORMAT, date -d, timedatectl status) work without sudo. Commands that change system state (date -s, timedatectl set-time, timedatectl set-timezone, hwclock --systohc) require root because they modify the system clock or the timezone configuration. The generator includes sudo where it is required.

Run timedatectl list-timezones for the modern systemd interface, or ls /usr/share/zoneinfo on any Unix system to browse the raw timezone files. The generator outputs the right command for your selected platform. Timezones use the Region/City format (for example America/New_York, Europe/London, Asia/Tokyo) as defined by the IANA Time Zone Database.