zoukankan      html  css  js  c++  java
  • 【Linux 运维】 date的使用

    date的使用

    一、常用时间格式

    #年、月、日  四位年大写,其余小写
    [root@localhost ~]# date +%Y    #长格式显示四位数年
    2018
    [root@localhost ~]# date +%y    #2位短格式显示
    18
    [root@localhost ~]# date +%m    #月
    10
    [root@localhost ~]# date +%d    #日
    06
    [root@localhost ~]# 
    #显示时、分、秒  大写字母表示
    [root@localhost ~]# date +%H    #时
    19
    [root@localhost ~]# date +%M    #分
    50
    [root@localhost ~]# date +%S    #秒
    42
    [root@localhost ~]# date +%s    #时间戳,距离1970年-01-01 00:00:00 过去多少秒
    1538826639
    
    #特殊格式显示
    [root@localhost ~]# date +%F    #特殊格式日期
    2018-10-06
    [root@localhost ~]# date +%T    #特殊格式时间
    19:50:53
    [root@localhost ~]# 
    [root@localhost ~]# date +"%F %T"     #指定格式连接
    2018-10-06 19:54:14
    [root@localhost ~]# date +"%Y/%m/%d %T" #指定格式显示
    2018/10/06 19:54:38
    [root@localhost ~]# 

    二、-d指定字符串所描述的时间

    [root@localhost ~]# date +%F -d "-1 day"    #昨天
    2018-10-05
    [root@localhost ~]# date +%F -d "yesterday"    #昨天
    2018-10-05
    [root@localhost ~]# date +%F -d "-2 day"    #前天
    2018-10-04
    [root@localhost ~]# date +%F -d "+1 day"    #明天
    2018-10-07
    [root@localhost ~]# date +%F -d "tomorrow"    #明天
    2018-10-07
    [root@localhost ~]# date +%F -d "+2 day"    #后天
    2018-10-08
    [root@localhost ~]# date +%F -d "1 month"   #一个月后
    2018-11-06
    [root@localhost ~]# date +%F -d "1 year"    #一年后
    2019-10-06

    三、-s 设定时间

    [root@localhost ~]# date -s 20181005
    [root@localhost ~]# date -s 00:00:01
    #一下三种格式输出的结果都是一样的,跟默认的一致
    [root@localhost ~]# date -s “00:00:01 20181005"
    [root@localhost ~]# date -s “00:00:01 2018-10-05"
    [root@localhost ~]# date -s “00:00:01 2018/10/05"

    四、显示日期换行

    [root@localhost ~]# date +%D%n%T
    10/06/18
    20:07:51
    [root@localhost ~]# date +%F%n%T
    2018-10-06
    20:07:59
    [root@localhost ~]# 
    [root@localhost ~]# date +"%Y/%m/%d"%n"%H:%M:%S"
    2018/10/06
    20:09:34
    [root@localhost ~]# 
  • 相关阅读:
    基础表达式和运算符
    原型链(_proto_) 与原型(prototype) 有啥关系?
    插件模板
    加减plugin
    原生选项卡、手风琴
    前端基础问题(有答案)
    结构图
    Java环境配置小记
    函数
    砝码称重
  • 原文地址:https://www.cnblogs.com/yangleitao/p/9748327.html
Copyright © 2011-2022 走看看