Syntax
Open a terminal and type the following command:date
Sat Nov 7 22:44:59 IST 2009
You can format the date as follows in dd-mm-yy format:date +"%d-%m-%y"
07-11-09
Simply display the current time:date "+%T"
00:02:12
To print the date of the day before yesterday, run:date --date='2 days ago'
Want to see the day of year of Christmas in the current year? Try:date --date='25 Dec' +%j
Display the current full month name and the day of the month:date '+%B %d'
Display date and time in Linux using the timedatectl
Most modern Linux distro with systemd use the timedatectl command. It is used to query and change the system clock and its settings, and enable or disable time synchronization services. All you have to do is type the following command:$ timedatectl
日期写全:
Syntax
The date command syntax is:
date +"%FORMAT" date +"%y" date +"%Y"
Examples
Type the following commands:
date +"%Y" date +"%y" ## Store to a shell variable ## mydate=$(date +'%Y') myyear=`date +'%Y'` echo "Year = $mydate" echo "Year = $myyear"
去掉0:
date '+%Y.%-m.%-d.%-H.%-M.%-S'