获取当前日期的前一天或几天
来源:互联网 发布:电商产品数据分析 编辑:程序博客网 时间:2024/05/16 12:14
封装脚本 last_day.sh
#!bin/sh
# ydate: A Bourne shell script that
# prints yestarday's date
# Output Form: Month Day Year
# From Focus on Unix: http://unix.about.com
# Author:chenhy
# Set the current month day and year.
month=`date +%m`
day=`date +%d`
year=`date +%Y`
sub_day(){
# Add 0 to month. This is a
# trick to make month an unpadded integer.
month=`expr $month + 0`
# Subtract one from the current day.
day=`expr $day - 1`
# If the day is 0 then determine the last
# day of the previous month.
if [ $day -eq 0 ]; then
# Find the preivous month.
month=`expr $month - 1`
# If the month is 0 then it is Dec 31 of
# the previous year.
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
# If the month is not zero we need to find
# the last day of the month.
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
#echo $year$month$day
if [ `expr $month - 10` -lt 0 ]; then
month="0"$month
fi
}
before_day=$1
#echo $before_day
while [ 0 -lt $before_day ]
do
#echo '-------'
sub_day
before_day=`expr $before_day - 1`
#echo $before_day
done
if [ `expr $day - 10` -lt 0 -a $1 -ne 0 ]; then
day="0"$day
else
day=$day
fi
#if [ `expr $month - 10` -lt 0 ]; then
# month="0"$month
#fi
echo $year$month$day
exit 0
##############################################################
脚本封装完成后,比如要获取前一天日期:day1=`ksh last_day.sh 1`
echo $day1
获取前几天日期,以此类推。
- 获取当前日期的前一天或几天
- 获取当前日期的前一天
- 获取当前日期前一天
- 用js获取当前日期的前一天
- 获取指定格式的日期字符串,包括前一天或者几天
- mysql 获取当前日期前一天
- Java中根据当前的日期获取前一天的日期
- js获取当前日期的前一天、一月、一年的日期
- 批处理 获取当前系统日期前一天的日期
- js获取当前日期、前一天、后一天的日期
- BAT批处理 获取当前系统日期前一天的日期
- 获取指定日期的后一天或前一天的日期
- js获取当前日期的前后几天
- Linux下如何用date获取当前日期的前一天
- java 获取当前日期的前三月,前一天
- java获取当前时间及前一天的日期
- 如何用批处理文件写:获取当前日期的前一天
- 获取当前日期的前一天和后一天
- 查看Data Guard同步--使用Broker
- Mac环境变量配置错了以后初始化的方法
- Android获取屏幕宽度的4种方法
- 如何使用阿里巴巴字体图标库
- 杀千刀的eclipse中java源代码文件中文乱码问题
- 获取当前日期的前一天或几天
- iOS 编程的几个基本概念
- 4177: Mike的农场|最小割
- C++为什么要引入静态成员函数
- 关于UITableView
- java 死锁产生原因及解锁
- Android之Adapter结构
- 几种上传文件组件的性能比较
- 关于java学习的一些感受