shell脚本时间操作
来源:互联网 发布:玩客云 淘宝众筹 编辑:程序博客网 时间:2024/05/28 22:07
date +%s 可以得到UNIX的时间戳;
用shell将时间字符串与时间戳互转:
date -d "2010-10-18 00:00:00" +%s 输出形如:1287331200
而时间戳转换为字符串可以这样做:
date -d @1287331200 "+%Y-%m-%d" 输出形如:2010-10-18
如果需要得到指定日期的前后几天,可以:
1、seconds=`date -d "2010-10-18 00:00:00" +%s` #得到时间戳
2、seconds_new=`expr $seconds + 86400` #加上一天的秒数86400
用shell将时间字符串与时间戳互转:
date -d "2010-10-18 00:00:00" +%s 输出形如:1287331200
而时间戳转换为字符串可以这样做:
date -d @1287331200 "+%Y-%m-%d" 输出形如:2010-10-18
如果需要得到指定日期的前后几天,可以:
1、seconds=`date -d "2010-10-18 00:00:00" +%s` #得到时间戳
2、seconds_new=`expr $seconds + 86400` #加上一天的秒数86400
3、date_new=`date -d @$seconds_new "+%Y-%m-%d"` #获得指定日前加上一天的日前 等同于 date -d "1970-01-01 UTC "3423423234" seconds" +"%Y-%m-%d %H:%M:%S"
date -d"-500years" 等同于date --date="500 years ago"
date -d"500years ago"
2个月3天之后可以这样写:
date -d"+2month+3day"
1 0
- shell脚本时间操作
- shell脚本时间操作
- shell 脚本中的时间操作
- shell脚本专家指南--日期时间操作
- shell脚本-有关时间的操作
- shell 脚本 时间
- 【SHELL脚本】文件操作
- shell脚本文件操作
- shell脚本操作数据库
- shell脚本字符串操作
- shell脚本操作数据库
- Java操作shell脚本
- 常用shell脚本操作
- shell操作数据库脚本
- shell脚本操作mysql
- shell脚本操作oracle
- shell 脚本日期操作
- shell 脚本字符串操作
- 两大数相乘 -- javascript 实现
- 浅谈如何减小汽车发动机舱的异常噪声过大
- 一个人的项目组
- C++虚继承研究-1
- poj 1562 (bfs)
- shell脚本时间操作
- CloudStack 4.2安装文档(Agent)
- Jquery Aajx异步提交系列
- Hadoop的实质是什么
- IOS 推送机制详解,兼容IOS8的推送
- 学徒浅析Android开发:第七讲——数据存储之SharedPreferences
- LeetCode: Largest Rectangle in Histogram [084]
- 指尖上的幸福
- struts2 使用redirect实现带参重定向显示action中的变量