1、下载安装busybox:

# wget http://busybox.net/downloads/busybox-1.29.3.tar.bz2
# tar -jxvf busybox-1.29..tar.bz2
# cd busybox-1.29.
# make defconfig //如果对根文件系统的大小不是很苛求,可以直接使用busybox的默认配置
# make
# make install 构建date链接
# ln -sf ./busybox ./date

busybox date参数详解

[busybox-1.29.]# ./date --help
BusyBox v1.29.3 (-- :: CST) multi-call binary. Usage: date [OPTIONS] [+FMT] [TIME] Display time (using +FMT), or set time [-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc- Output RFC- compliant date string
-I[SPEC] Output ISO- compliant date string
SPEC='date' (default) for date only,
'hours', 'minutes', or 'seconds' for date and
time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion Recognized TIME formats:
hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]
'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead

Linux系统中的date一般可以直接进行日期的相减,

例如: centos7系统

date 获取前一天的时间: date -d -1day     或者   date -d '1 day ago'

date 获取前一个月的时间: date -d '1 month ago'

date 获取前一年的时间: date -d '1 year ago'

而busybox date则不可以直接获取前一天的时间,,需要时间数字相减的方法来实现获取前一天的时间

例如: busybox date 获取前一天的时间:

考虑到当前时间是年度第一天1月1日的情况,代码如下:

year=`date +%Y`   // 获取当前时间的年份
month=`date +%m` // 获取当前时间的月份
day=`date +%d` // 获取当前时间的日期 if [[ "$day" == "" ]];then // 如果当前时间是1号 ,则考虑一下月份问题
if [[ "$month" == "" ]];then // 如果当前时间是1月1号,,获取的前一天则是去年的最后一天 ,所以年份需要减一,月份和日期则是12月31日
year=`expr $year - `
yesterday="${year}-12-31"
elif [[ "$month" == "" ]];then // 如果当前时间是3月1号,获取的前一天则是2月的最后一天,2月又分28天和29天,,所以需要和4取余,
year_type=`expr ${year} % `
if [[ "$year_type" == "" ]];then // 与4取余为0则为闰年,这一年的2月最后一天是29号,,取余不为0则为平年,2月的最后一天是28号
day=""
else
day=""
fi
yesterday="${year}-02-${day}"
// 1,3,5,7,8,10,12月均是31天
elif [[ "$month" == "" || "$month" == "" || "$month" == "" || "$month" == "" || "$month" == "" || "$month" == "" ]];then
month=`expr ${month} - `
yesterday="${year}-${month}-31"
elif [[ "$month" == "" ||"$month" == "" || "$month" == "" || "$month" == "" ]];then
month=`expr ${month} - `
yesterday="${year}-${month}-30" fi
else
yesterday=${year}-${month}-`expr ${day} - `
fi echo $yesterday

busybox date 时间的加减的更多相关文章

  1. java中可以对时间进行加减处理,有时候不用在sql语句中处理

    String ssny = (String) pd.get("ssny");   SimpleDateFormat simpleDateFormat=new SimpleDateF ...

  2. 【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算

    在Python中,与时间处理相关的模块有:time.datetime以及calendar.学会计算时间,对程序的调优非常重要,可以在程序中狂打时间戳,来具体判断程序中哪一块耗时最多,从而找到程序调优的 ...

  3. linux的date命令使用指定时间的加减方法与异常

    在一般网页里,date命令减时间方法为: date -d '-100 days' 我的需求是,在指定时间上减8小时.按一般理解来看,命令写成如下样子(有异常错误的写法): date -d " ...

  4. MySQL 时间函数加减计算

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期 + 时间(date + time) 函数:now() mysql> select now();+———————+| now() |+ ...

  5. Java对日期Date类进行加减运算,年份加减,月份加减

      import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; public class Da ...

  6. 【转】Java对日期Date类进行加减运算,年份加减,月份加减

    import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; public class Date ...

  7. xxxx-xx-xx的时间的加减

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...

  8. Oracle计算时间函数(对时间的加减numtodsinterval、numtoyminterval) (转)

    原文来自:http://blog.itpub.net/756652/viewspace-697256/ 11g interval分区,按天分区,需要用到函数numtodsinterval.   cre ...

  9. Oracle 时间处理(加减)

    一. 类似SQL SERVER中DateAdd select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate ...

随机推荐

  1. Servlet(2):Requset/Response Encoding and Filter

    Requset/Response Encoding 表单提交分GET和POST,接下来分开讨论. (1)GET/URL提交的数据 在 Tomcat中,默认情况下使用"URIEncoding& ...

  2. Springboot学习—CommandLineRunner接口(转载)

    前言 Spring boot的CommandLineRunner接口主要用于实现在应用初始化后,去执行一段代码块逻辑,这段初始化代码在整个应用生命周期内只会执行一次. 如何使用CommandLineR ...

  3. C#.NET中对称和非对称加密、解密方法汇总--亲测可用

    C#.NET中对称和非对称加密.解密方法汇总--亲测可用   在安全性要求比较高的系统中都会涉及到数据的加密.解密..NET为我们封装了常用的加密算法,例如:MD5,DES,RSA等.有可逆加密,也有 ...

  4. PI膜热作用机理

    一.热分析法: 二.研究成果 1.PI膜热老化机理 实验条件:8根500w的碘钨灯加热,200倍光学显微镜观察,PI膜的技术指标 实验概述:本研究分别以150 ℃ ,  175 ℃ , 200 ℃ , ...

  5. 11个顶级 JavaScript 日历插件

    参考链接:https://mp.weixin.qq.com/s?__biz=MzI3NzIzMDY0NA==&mid=2247487050&idx=1&sn=e1cf66726 ...

  6. FTL-SLC&MTC&TLC

    1.博客 SLC.. http://diybbs.zol.com.cn/67/231_661182.html 2.FTL --作者在普及了一些FTL基本知识后,主要分析了在linux上实现的途径 ht ...

  7. [计蒜客T2237]魔法_树

    魔法 题目大意: 数据范围: 题解: 这个题挺好玩的 可以用反证法,发现所有叶子必须都得选而且所有叶子都选了合法. 故此我们就是要使得,一次操作之后使得叶子的个数最少. 这怎么弄呢? 我们发现,如果一 ...

  8. DashBoard-身份验证

    dashboard1.7.1版本之后,新增了用户登录认证的功能. 默认dashboard会跳转到登录页面: 我们可以看到dashboard提供了Kubeconfig和token两种登录方式,我们可以直 ...

  9. Codeforces 1238D. AB-string

    传送门 求合法的串看一眼很不可做 考虑一下总方案减去不合法方案 考虑如何求不合法的串,首先串中连续的相同字符一定是回文串的一部分 然后考虑 $AB$ 交错的情况,发现对于某个 $A$ 它如果左右都有 ...

  10. Graph、DFS、BFS

    Graph.java package Graph; import LinearLIst.bag.Bag; import edu.princeton.cs.algs4.In; public class ...