Mastering the Linux ‘date’ Command: Display, Format, and Set System Time
This guide explains how to use the Linux date command to display the current date and time, customize output formats, and set the system clock, covering syntax, options such as -d, -s, -u, and practical examples for common tasks.
date: display or set date and time
Function description
The date command can display or set the system’s date and time. When displaying, users can specify a format prefixed with a plus sign followed by format specifiers.
Without a leading plus sign, the command sets the time. The time format is MMDDhhmm[[CC]YY][.ss] , where MM is month, DD day, hh hour, mm minute, CC first two digits of year, YY last two digits, ss seconds.
Command syntax
date [options] [display format] (format must start with +)Option meanings
-d <string>: display the time described by the given string instead of the current time. -s <string>: set the system time to the time described by the string. -r <file>: display the last modification time of the file. -u: display or set Coordinated Universal Time (UTC). -f <datefile>: read time descriptions line by line from a date file. --help: show help information. --version: show version number.
Examples
(1) Show current date and time.
# date
2021年 09月 28日 星期二 23:40:24 CST(2) Show current date and time in a specific format.
# date +"%Y-%m-%d %H:%M:%S"
2021-09-28 23:41:27(3) Set the computer date and time to September 10, 2029 11:12.
# date 0910111229
2029年 09月 10日 星期一 11:12:00 CST(4) Set the computer date to November 12, 2025.
# date -s 251112
2025年 11月 12日 星期三 00:00:00 CST(5) Set the computer time to 13:14:15.
# date -s 13:14:15
2025年 11月 12日 星期三 13:14:15 CST(6) Display the date and time with a custom format.
# date "+今天的日期是%x, 当前时间是%X"
今天的日期是2021年09月28日, 当前时间是22时43分30秒Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
