今天写程序的时候,突然发现了很早以前写的获取月份天数的函数,经典的switch版,但是获得上月天数的时候,我只是把月份-1了,估计当时太困了吧,再看到有种毛骨悚然的感觉,本来是想再处理一下的,但是一想肯定还有什么超方便的方法,于是找到了下面这个版本,做了一点小修改. 获取本月日期: function getMonth($date){ $firstday = date("Y-m-01",strtotime($date)); $lastday = date("Y-m-d"…
今天写程序的时候,突然发现了很早以前写的获取月份天数的函数,经典的switch版,但是获得上月天数的时候,我只是把月份-1了,估计当时太困了吧,再看到有种毛骨悚然的感觉,本来是想再处理一下的,但是一想肯定还有什么超方便的方法,于是找到了下面这个版本,做了一点小修改. 获取本月日期: 复制代码代码如下: function getMonth($date){     $firstday = date("Y-m-01",strtotime($date));     $lastday = dat…
${TodayDate} evaluate datetime.date.today().strftime('%Y%m%d') datetime ${CurrentMonthFirstDay} evaluate datetime.date.today().replace(day=1) datetime #返回当月的1号${LastMonthFirstDay} evaluate (datetime.date.today().replace(day=1) - datetime.timedelta(1)…
时间戳格式: //获取今日开始时间戳和结束时间戳 $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; //获取昨日起始时间戳和结束时间戳 $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); $endYesterday=mktime(0,0,0,d…
在mysql数据库中使用int类型保存时间戳时,一般在程序中可能会用到统计当日,当月的一些数据.那么可以用如下的方式限定时间范围:   //当日销售 $today_start = strtotime(date('Y-m-d 00:00:00')); $today_end = strtotime(date('Y-m-d 23:59:59'));   //本月销售 $month_start = strtotime(date("Y-m-01")); $month_end = strtotim…
获取本月日期:   代码如下: function getMonth($date){ $firstday = date("Y-m-01",strtotime($date)); $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); return array($firstday,$lastday); } $firstday是月份的第一天,假如$date是2014-2这样的话,$…
<?php //echo $_SERVER['PHP_SELF']; //define('ROOT_PATH',str_replace($_SERVER['PHP_SELF'],'',str_replace('\\', '/', __FILE__))); /** * 获取统计时间 * @param $type * 1 上月 * 2 本月 * 3 近15天 * 4 近30天 * @return array */ function getDateInfo($type) { $data = array…
javascript根据当前日期获取上个月日期 function lastMonthDate(){ var Nowdate = new Date(); var vYear = Nowdate.getFullYear(); var vMon = Nowdate.getMonth() + 1; var vDay = Nowdate.getDate(); //每个月的最后一天日期(为了使用月份便于查找,数组第一位设为0) var daysInMonth = new Array(0,31,28,31,3…
// 上个月的时间戳 $thismonth = date('m'); $thisyear = date('Y'); if ($thismonth == 1) { $lastmonth = 12; $lastyear = $thisyear - 1; } else { $lastmonth = $thismonth - 1; $lastyear = $thisyear; } $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; $lastEndD…
正常来说,PHP是有一个很方便的函数可以获取上个月时间的 strtotime (PHP 4, PHP 5, PHP 7) strtotime - 将任何英文文本的日期时间描述解析为 Unix 时间戳 说明 ¶ int strtotime ( string $time [, int $now = time() ] ) 今天是2016-10-31日,所以strtotime('-1 month'),应该是9月30日 echo date('Y-m-d',strtotime('-1 month')); 可…