当前位置:网站首页>Addition and subtraction of busybox date time
Addition and subtraction of busybox date time
2022-07-19 06:09:00 【xp5xp6】
1、 Download and install busybox:
Copy code
wget http://busybox.net/downloads/busybox-1.29.3.tar.bz2
tar -jxvf busybox-1.29.3.tar.bz2
cd busybox-1.29.3
make defconfig // If the size of the root file system is not very demanding , You can use it directly busybox Default configuration
make
make install
structure date link
ln -sf ./busybox ./date
Copy code
busybox date Parameters,
Copy code
[busybox-1.29.3]# ./date --help
BusyBox v1.29.3 (2019-11-25 11:00:35 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-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 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
Copy code
Linux In the system date Generally, you can directly subtract dates ,
for example : centos7 System
date Get the time of the day before : date -d -1day perhaps date -d ‘1 day ago’
date Get the time of the previous month : date -d ‘1 month ago’
date Get the time of the previous year : date -d ‘1 year ago’
and busybox date You can't get the time of the previous day directly ,, You need the method of subtracting time numbers to obtain the time of the previous day
for example : busybox date Get the time of the day before :
Considering that the current time is the first day of the year 1 month 1 What happened in Japan , The code is as follows :
Copy code
year=date +%Y // Get the year of the current time
month=date +%m // Get the month of the current time
day=date +%d // Get the date of the current time
if [[ “ d a y " = = " 01 " ] ] ; t h e n / / Such as fruit When front when between yes 1 Number , be Examination Consideration One Next month Share ask topic i f [ [ " day" == "01" ]];then // If the current time is 1 Number , Then consider the month if [[ " day"=="01"]];then// Such as fruit When front when between yes 1 Number , be Examination Consideration One Next month Share ask topic if[["month” == “01” ]];then // If the current time is 1 month 1 Number ,, The day before the acquisition is the last day of last year , So the year needs to be reduced by one , The month and date are 12 month 31 Japan
year=expr $year - 1
yesterday=“ y e a r − 12 − 31 " e l i f [ [ " {year}-12-31" elif [[ " year−12−31"elif[["month” == “03” ]];then // If the current time is 3 month 1 Number , The day before the acquisition is 2 Last day of the month ,2 Month and minute 28 Days and 29 God ,, So we need and 4 Remainder ,
year_type=expr ${year} % 4
if [[ “ y e a r t y p e " = = " 0 " ] ] ; t h e n / / And 4 take more than by 0 be by Leap year , this One year Of 2 month most after One God yes 29 Number , , take more than No by 0 be by flat year , 2 month Of most after One God yes 28 Number d a y = " 29 " e l s e d a y = " 28 " f i y e s t e r d a y = " year_type" == "0" ]];then // And 4 Take remainder as 0 It's a leap year , This year's 2 The last day of the month is 29 Number ,, The remainder is not 0 It is a normal year ,2 The last day of the month is 28 Number day="29" else day="28" fi yesterday=" yeartype"=="0"]];then// And 4 take more than by 0 be by Leap year , this One year Of 2 month most after One God yes 29 Number ,, take more than No by 0 be by flat year ,2 month Of most after One God yes 28 Number day="29"elseday="28"fiyesterday="{year}-02- d a y " / / 1 , 3 , 5 , 7 , 8 , 10 , 12 month all yes 31 God e l i f [ [ " {day}" // 1,3,5,7,8,10,12 Every month is 31 God elif [[ " day"//1,3,5,7,8,10,12 month all yes 31 God elif[["month” == “02” || “ m o n t h " = = " 04 " ∣ ∣ " month" == "04" || " month"=="04"∣∣"month” == “06” || “ m o n t h " = = " 08 " ∣ ∣ " month" == "08" || " month"=="08"∣∣"month” == “09” || “$month” == “11” ]];then
month=expr ${month} - 1
yesterday=" y e a r − {year}- year−{month}-31"
elif [[ “ m o n t h " = = " 05 " ∣ ∣ " month" == "05" ||" month"=="05"∣∣"month” == “07” || “ m o n t h " = = " 10 " ∣ ∣ " month" == "10" || " month"=="10"∣∣"month” == “12” ]];then
month=expr ${month} - 1
yesterday=" y e a r − {year}- year−{month}-30"
fi
else
yesterday= y e a r − {year}- year−{month}-expr ${day} - 1
fi
echo $yesterday
Copy code
Try to be an excellent engineer
边栏推荐
- uboot 编译前的配置命令make config分析
- 带透明png转换成c数组
- 嵌入式C语言重点(const、static、voliatile、位运算)
- 4-channel encoder pulse counter, 8-Channel do, Modbus TCP module
- HRA 1~12w series 12V wide voltage 9~18v to ± 250VDC boost converter
- 2022/07/12 学习笔记 (day05)循环
- 4-channel encoder pulse counter, speed measurement, 8-Channel do, Modbus TCP data acquisition module
- 2021-11-10 micropyton tb6600 step drive class
- MySQL Workbench基本使用【创建一个数据库】
- 自动补全 & (自定义)拼音分词器 & 搜索时注意事项
猜你喜欢

数学基础课2_欧拉函数,线性筛,扩欧

Rs-485/232 to 4-20ma/0-10v isolated d/a converter

2021-09-15

Thermal resistance PT100 cu50 isolation converter to 4-20mA analog output temperature transmitter 0-10V

4-channel encoder pulse counter, 8-Channel do, Modbus TCP module

2022/07/11 第五小组 丁帅 学习笔记 day04

Introduction to basic knowledge of Minio

EasyDarawin流媒体服务器介绍
![[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning](/img/65/fbb975491d4abd5d1babdf000513e2.png)
[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning

2022/07/10 第五小组 丁帅 学习笔记 day03
随机推荐
Loadng class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdb
Ht7727 ht7730 ht7733 ht7737 ht7750 asynchronous DCDC boost IC
4-channel encoder pulse counter, 8-Channel do, Modbus TCP module
Speed sensor signal isolation, acquisition and transformation, sine wave and sawtooth wave signal input, square wave signal output, signal converter
c语言 指定日期开始多少天 显示
Golang multi project workspace construction
Decorate Apple Tree
Acwing game 57 (AK)
[详细教程安装][配置] VsCode中关于Eslint的辅助插件
【力扣】翻转二叉树
Wireless charging chip IC
[transfer] Darwin streaming server core code analysis
vscode one dark和c扩展变量颜色冲突 设置settings.json如下即可
filezilla传输虚拟机速度慢解决方法
MySQL workbench basically uses [create a database]
Complete scheme diagram of lth7 five pin chip fs4054 charging circuit principle
Acwing game 58 (AK)
Darwin's analytical experience
busybox date 时间的加减
DSL实现Bucket聚合