#!/bin/sh
#根据当前时间获取当前月份的第一天零点时间戳和下一月份零点时间戳
# ./getMonth.sh
#根据输入的时间戳
#./getMonth.sh -t 1345600232
#根据输入的日期
#./getMonth.sh -d 2012-12
if [ $1 ]
then
if [ $1 = '-t' ]
then
if [ $2 ]
then
month=`date -d@$2 +%Y-%m`
else
month=`date +%Y-%m`
fi
elif [ $1 = '-d' ]
then
if [ $2 ]
then
month=$2
else
month=`date +%Y-%m`
fi
else
month=`date +%Y-%m`
fi
else
month=`date +%Y-%m`
fi
startMonth=${month}-01
nextMonth=`date -d "${startMonth} next month" +%Y-%m`-01
startTime=`date -d "$startMonth" +%s`
endTime=`date -d "$nextMonth" +%s`
echo $month
echo `date -d@$startTime "+%Y-%m-%d %H:%M:%S"`
echo $startTime
echo `date -d@$endTime "+%Y-%m-%d %H:%M:%S"`
echo $endTime