zoukankan      html  css  js  c++  java
  • linux的date的几个例子

    shell脚本为test.sh:

    input=$1
    echo "sdfa:${input}"
    echo ${input}
    echo "dfadf"${input}
    echo dfasdf{input}
    echo $(date -d "${input}" +%Y)
    echo $(date -d "${input}" +%m)
    echo $(date -d "${input}" +%V)

    ./test.sh 2013-07-15 的执行结果为

    sdfa:2013-07-15
    2013-07-15
    dfadf2013-07-15
    dfasdf{input}
    2013
    07
    29#第29周

    %U 周 (00-53) 星期日是一周的第一天
    %u 周 (00-53) 星期一是一周的第一天
    %V 周 (01-53) 星期日是一周的第一天,与 %X 使用
    %v 周 (01-53) 星期一是一周的第一天,与 %x 使用

    注意date -d 命令中

    1、空格的位置,还有起各个符号与参数间是否有空格

    2、日期可以不加引号,date命令中的变量也可以不加引号

    dateinput="2013-01-31"#等号前后不能有空格
    date -d "2013-07-31" +%V
    date -d "${dateinput}" +%Y
    date -d "${dateinput}" +%V
    date -d "${dateinput} -9 weeks" +%Y%m%d

    dateinput=$1#注意等号前后不能有空格
    year=$(date -d "${dateinput}" +%Y)
    month=$(date -d "${dateinput}" +%m)
    first_day_of_month=$(date -d "${dateinput}" +%Y%m01)
    first_day_of_next_month=$(date -d "${dateinput} +1 month" +%Y%m01)
    last_day_of_month=$(date -d "${first_day_of_next_month} -1 days" +%Y%m%d)

    #echo "the last day:${last_day_of_month}"

    dateinput2=$2
    begin_date=$(date -d "${dateinput} +${dateinput2} month" +%Y%m01)
    next_month_day=$(date -d "${begin_date} +1 month" +%Y%m%d)
    end_date=$(date -d "${next_month_day} -1 days" +%Y%m%d)

    echo "begin_date:${begin_date}"
    echo "end_date:${end_date}"

  • 相关阅读:
    JavaScript 位运算总结&拾遗
    leetcode
    leetcode
    【位运算经典应用】 寻找那个唯一的数
    归并排序 JavaScript 实现
    【位运算经典应用】 求二进制逆序
    Odoo仪表盘详解
    Odoo启动运行参数(script运行参数,不是运行配置文件)
    Odoo中的self详解
    【Odoo 8开发教程】第二章:Odoo生产环境部署设置
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205644.html
Copyright © 2011-2022 走看看