设为首页 加入收藏

TOP

Shell中获取两个日期的间隔时间
2014-11-24 12:31:36 来源: 作者: 【 】 浏览:2
Tags:Shell 获取 两个日期 间隔 时间

Shell获取昨天天所在季度的第一天,到昨天的日期间隔
#!/bin/sh
day=`date -d "1 days ago " "+%Y%m%d"`;
year=`expr substr ${day} 1 4`;
month=`expr substr ${day} 5 2`;
s_date=$year"0101"
if [ "$month" == "01" ] || [ "$month" == "02" ] || [ "$month" == "03" ];then
s_date=$year"0101"
elif [ "$month" == "04" ] || [ "$month" == "05" ] || [ "$month" == "06" ];then
s_date=$year"0401"
elif [ "$month" == "07" ] || [ "$month" == "08" ] || [ "$month" == "09" ];then
s_date=$year"0701"
elif [ "$month" == "10" ] || [ "$month" == "11" ] || [ "$month" == "12" ];then
s_date=$year"1001"
fi
e_date=$day
sys_s_data=`date -d "$s_date" +%s`
sys_e_data=`date -d "$e_date" +%s`
interval=`expr $sys_e_data - $sys_s_data`
daycount=`expr $interval / 3600 / 24 + 1`


echo $daycount 执行输出:
62


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Mac OS X Lion 下编译Android 源码 下一篇Java的序列化机制原理分析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++ Lambda表达式保 (2025-12-26 05:49:45)
·C++ Lambda表达式的 (2025-12-26 05:49:42)
·深入浅出 C++ Lambda (2025-12-26 05:49:40)
·C语言指针从入门到基 (2025-12-26 05:21:36)
·【C语言指针初阶】C (2025-12-26 05:21:33)