最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Linux命令显示当前系统时间

Linux crifan 1606浏览 0评论
折腾:
【未解决】WordPress的php的log文件php-fpm.log太大
期间,希望在CentOS的Linux命令行中显示当前时间
linux command show current time
Display Date And Time In Linux – nixCraft
Linux: Bash Get Time – nixCraft
linux – How can I get the current date and time in the terminal and set a custom command in the terminal for it? – Stack Overflow
[root@crifan log]# date YYYYMMDD-HH:MM:SS
date: invalid date ‘YYYYMMDD-HH:MM:SS’
[root@crifan log]# date +%Y%m%d%H%M%S
20201031120040
[root@crifan log]# date +%Y%m%d %H%:M:%S
date: extra operand ‘%H%:M:%S’
Try 'date --help' for more information.
[root@crifan log]# date "+%Y%m%d %H%:M:%S"
20201031 12%:M:59
[root@crifan log]# date +%Y%m%d_%H%:M:%S
20201031_12%:M:26
[root@crifan log]# date +%Y%m%d%H:%M:%S
2020103112:01:42
[root@crifan log]# date +%Y%m%d_%H:%M:%S
20201031_12:01:48
[root@crifan log]# date "+%Y%m%d %H:%M:%S"
20201031 12:02:01
【总结】
此处Linux中显示当前时间的命令是:
date
输出:
Sat Oct 31 12:03:50 CST 2020
想要格式化可以用:
date +%Y%m%d_%H:%M:%S
输出:
20201031_12:04:49
如果格式中间有空格,则需要加上双引号:
 date "+%Y%m%d %H:%M:%S"
输出:
20201031 12:03:57
即可。

转载请注明:在路上 » 【已解决】Linux命令显示当前系统时间

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.192 seconds, using 22.15MB memory