php获取当前月月初至月末的时间戳,上个月月初至月末的时间戳

简介:

当前月

复制代码
<?php
$thismonth = date('m');
$thisyear  = date('Y');
$startDay = $thisyear . '-' . $thismonth . '-1';
$endDay   = $thisyear . '-' . $thismonth . '-' . date('t', strtotime($startDay));
$b_time       = strtotime($startDay);
$e_time       = strtotime($endDay);
复制代码

 

上一月

复制代码
<?php
$thismonth = date('m');
$thisyear  = date('Y');
if ($thismonth == 1) {
    $lastmonth = 12;
    $lastyear  = $thisyear - 1;
} else {
    $lastmonth = $thismonth - 1;
    $lastyear  = $thisyear;
}
$lastStartDay = $lastyear . '-' . $lastmonth . '-1';
$lastEndDay   = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay));
$b_time = strtotime($lastStartDay);
$e_time = strtotime($lastEndDay);
复制代码

这里对关键的就是date函数中的t,它是用来获取当前月所含天数的,28天,29天,30天,31天。含有多少天,月底就是多少号。




本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5056891.html,如需转载请自行联系原作者

相关文章
|
10月前
|
PHP
php计算时间差转化时间戳函数strtotime
php计算时间差转化时间戳函数strtotime
47 0
|
7月前
|
Unix PHP
PHP时间戳如何操作,以及如何拿到时间
PHP时间戳如何操作,以及如何拿到时间
|
10月前
|
PHP
php时间戳超过2038年的解决方案
php时间戳超过2038年的解决方案
62 0
|
存储 Java PHP
Java存储数据库中时间戳和php操作数据库时间戳的关系
Java存储数据库中时间戳和php操作数据库时间戳的关系
123 0
Java存储数据库中时间戳和php操作数据库时间戳的关系
PHP:时间戳time和日期格式字符串转换date
PHP:时间戳time和日期格式字符串转换date
PHP:time时间戳和str字符串相互转换
PHP:time时间戳和str字符串相互转换
107 0
|
PHP
PHP获取当前0时的时间戳
PHP获取当前0时的时间戳
144 0
|
PHP
PHP时间戳转时间格式,时间格式转xx小时前
PHP时间戳转时间格式,时间格式转xx小时前
108 0
|
PHP
php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
869 0
|
PHP
PHP获取今天,昨天,本月,上个月,本年 起始时间戳
PHP获取今天,昨天,本月,上个月,本年 起始时间戳
899 2