当前位置:网站首页>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
边栏推荐
- 【力扣】单值二叉树
- Fs68001 wireless charging SOC chip has simple periphery and schematic diagram of 5W wireless charging scheme
- golang 多项目工作区搭建
- 嵌入式C语言重点(const、static、voliatile、位运算)
- [bjoi2019] platoon formation (Group backpack)
- Guess The String (二分,交互)
- 2021 - 09 - 15
- Boost dc/dc converter
- Low power LDO linear regulator IC
- Qtss callback routine
猜你喜欢

數學基礎課2_歐拉函數,線性篩,擴歐

Golang multi project workspace construction

3.7V lithium battery boost to 5v1a, fs2114 boost conversion chip design layout

RestClient-多条件聚合

2021-09-15
![[detailed tutorial installation] [configuration] auxiliary plug-ins about eslint in vscode](/img/d4/31272772b96d3e2f702da74478fd95.png)
[detailed tutorial installation] [configuration] auxiliary plug-ins about eslint in vscode

软考初、中、高级考试全体验

开源在线的MarkDown编辑器 --【Editor.md】

解决Cannot read properties of null (reading ‘pickAlgorithm‘)

Simple chrome script automatically skips the charging acknowledgment page after the video playback of station B ends
随机推荐
Solve cannot read properties of null (reading 'pickalgorithm')
Tips for using tp4054 charging IC -- used in conjunction with Zhongke Lanxun ab5365b
golang高并发特性goroutine介绍
【力扣】二叉树的前序遍历
Fs4061a (5V USB input, double lithium battery series application, 5V boost charging, 8.4v Management IC
Hra2460d-2w high voltage power supply high voltage module - high voltage - high precision hra2460d-2w
Darwin reflex summary
2022/07/12 学习笔记 (day05)循环
Decorate Apple Tree
MySQL Workbench基本使用 【创建一个数据表】
RestAPI实现自动补全 & 案例实现(搜索框输入进行自动补全)
三角形牧场 (0/1背包)
minio基础知识介绍
Introduction to basic knowledge of Minio
2022/07/14 学习笔记 (day07)数组
解决:无法加载文件 C:\Program Files\.. 因为在此系统上禁止运行脚本...
BusyBox 1.21.1 有udpsvd功能 可以编译成功 不干涉本机busybox方法
busybox date 时间的加减
5-17陕西科技大学的隐藏学生服务
QTSS数据类型