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 ~]# 
  • 相关阅读:
    Jmter组件执行顺序
    Win7X64位Seleniume+Eclipse+Pydev环境搭建
    软件测试自学指南---从入门到精通(转载)
    Python开发【第四篇】:Python基础之函数
    Python开发【第三篇】:Python基本数据类型
    Python开发【第二篇】:初识Python
    Python开发【第一篇】:目录
    个人作业3——个人总结(Alpha阶段)
    结对编程2——单元测试(201421123040,60,61)
    个人作业2——英语学习APP案例分析
  • 原文地址:https://www.cnblogs.com/yangleitao/p/9748327.html
Copyright © 2011-2022 走看看