Linux 里面怎么用命令行查看时间和日期

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'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值