[iyunv@localhost ~]# date +%Y-%m-%d #获取年月日
2015-08-20
[iyunv@localhost ~]# date +%y-%m-%d %H:%M:%S#需使用单引号引起来
date: extra operand `%H:%M:%S'
Try `date --help' for more information.
[iyunv@localhost ~]# date +'%y-%m-%d%H:%M:%S' #%y显示后两位年号
15-08-20 02:53:21
[iyunv@localhost ~]# date +%s #%s表示时间戳
1440010414
[iyunv@localhost ~]# date --date=20150820+%s #获取2015/08/20 的时间戳。
1440000000
# Unix时间戳(英文为Unixepoch, Unix time, POSIX time 或 Unix timestamp)
# 是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。
1
2
3
4
5
6
7
8
[iyunv@localhost ding]# date +%A #显示星期,%a简写星期
Thursday
[iyunv@localhost ~]# date -s 19:18:30 #设置时间
Sun Aug 9 19:18:30 CST 2015
[iyunv@localhost ~]# date -s 2015/08/23 #设置日期
Sun Aug 23 00:00:00 CST 2015
[iyunv@localhost ~]# date -s 2015-08-23 #设置日期
Sun Aug 23 00:00:00 CST 2015