shell 脚本的时间差计算
在某个时间点上增加一段时间
将时间转为时间戳,然后增加时间
[root@~]# date +%s -d '2017-05-27 12:0:0'
1495857600
[root@ ~]# new_time=`echo "1495857600 + 4800" | bc `
[root@ ~]# echo $new_time
1495862400
[root@ ~]# date +%Y-%m-%d\ %H:%M:%S -d "1970-01-01 UTC $new_time seconds"
2017-05-27 13:20:00
在某个时间点上减去一段时间
[root@~]# date +%s -d '2017-05-27 12:0:0'
1495857600
[root@ ~]# new_time=`echo "1495857600 - 4800" | bc `
[root@ ~]# echo $new_time
631122061
[root@ ~]# date +%Y-%m-%d\ %H:%M:%S -d "1970-01-01 UTC $new_time seconds"
2017-05-27 10:40:00
计算时间差
[root@ ~]# echo $((` date +%s -d '2017-05-27 17:00:00'` - `date +%s -d '2017-05-27 13:00:00'`))
14400
shell 脚本的时间差计算的更多相关文章
- shell脚本示例:计算毫秒级、微秒级时间差
bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 有时候需要计算命令的执行时间长度,可以使用time命令,虽然t ...
- Shell脚本之六 数学计算
前面一节Shell篇之五 基本运算符介绍了常见的 Shell 算术运算符,这节介绍 Shell 的数学计算.Shell 和其它编程语言不同,Shell 不能直接进行算数运算,必须使用数学计算命令. 下 ...
- shell脚本通过子网掩码计算出掩码位数
子网掩码格式为255.255.255.0可以通过以下脚本计算掩码位数 #!/bin/sh #maskdigits.sh mask maskdigits () { a=$(echo "$1&q ...
- Shell 脚本计算时间差
在shell脚本中统计程序执行完毕所需要的时间不像在java中使用System.currentTimeMillis()方便 稍微记录一下,以供备用,免得又去花时间想(统计程序执行消耗多少s): sta ...
- Shell脚本笔记(三)shell中的数学计算
shell中的数学计算 一.使用方括号 #!/bin/bash a= b= c= res=$[$a * ($c-$b)] echo $res 二.使用(()) +)) ((i=+)) b=$((-*) ...
- shell脚本中用到的计算
在shell脚本中计算一般会涉及到let.$(()).$[].bc(另扩展expr).其中let.$(()).$[]都是用来做基本整数运算,bc可以用来做浮点运算. (1).let.$(()).$[] ...
- shell脚本计算Linux网卡流量
本文介绍了计算linux网卡流量的一个shell脚本,一个通过固定间隔时间获取ifconfig eth0 的字节值而计算出网卡流量的方法,有需要的朋友参考下. 使用shell脚本计算Linux网卡流量 ...
- Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
本文为博主原创,转载请注明出处: 最近在进行压测,为了观察并定位服务性能的瓶颈,所以在代码中很多地方加了执行耗时的日志,但这种方式只能观察,却在压测的时候,不太能准确的把握代码中某些方法的性能,所以想 ...
- Linux之Shell脚本计算命令行的所有和
问题:设计一个Shell脚本:求命令行上所有整数和 Shell代码: 调用add.sh脚本结果:
随机推荐
- 【Python】-NO.98.Note.3.Python -【Python3 解释器、运算符】
1.0.0 Summary Tittle:[Python]-NO.98.Note.3.Python -[Python3 解释器] Style:Python Series:Python Since:20 ...
- CMB面试准备-基础
1.简述 private. protected. public. internal 修饰符的访问权限 private : 在类的内部才可以访问. protected : 保护成员,该类内部和继承类中可 ...
- centos make error: fatal error: curses.h: No such file or directory
yum install ncurses.x86_64 yum install ncurses-devel.x86_64 yum install ncurses-libs.x86_64 yum inst ...
- cocos2d-x JS 复选按钮checkBox的单选与多选
var HZ_createRoom = jx.BaseView.extend({//红中麻将 ctor : function() { this._super(); this.addLayout(res ...
- Python基础(三)Mysql数据库安装及使用
在python下使用mysql需要: 1.安装mysql 2.安装python pymysql包(pymysql包支持py3 跟mysqldb用法差不多) 一.安装mysql mysql下载地址:h ...
- vsftp
[安装vsftpd]安装vsftpd工具步骤 1 安装vsftpd组件 [root@bogon ~]# yum -y install vsftpd 安装完后,有/etc/vsftpd/vsftpd ...
- gitlab覆盖率
https://danny50610.blogspot.com/2017/09/gitlab-ci-phpunit-coverage.html
- Lua用一维数组存储一个n阶方阵,输出这个方阵的正对角线上的数的和与反对角线上的数的和的差的绝对值。
arr = {, , , , , , , , -} function diagonalDifference(arr) dimesion = math.sqrt(#arr) arr1 = {} sum1 ...
- Yii ActiveRecord生命周期
- STL容器之deque
[1]deque容器 deque 是对 vector 和 list 优缺点的结合,它是处于两者之间的一种容器. [2]deque方法集 应用示例代码: #include <deque> # ...