<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>时间获取 &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/%E6%97%B6%E9%97%B4%E8%8E%B7%E5%8F%96/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 07:19:27 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>php获取指定周期</title>
		<link>https://www.mudbest.com/php%e8%8e%b7%e5%8f%96%e6%8c%87%e5%ae%9a%e5%91%a8%e6%9c%9f/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Fri, 18 May 2012 01:36:38 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[时间获取]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=1081</guid>

					<description><![CDATA[获取本周周一、周日时间，上周周一、周日时间，本月第一天，本月最后一天，上个月第一天，最后一天时间]]></description>
										<content:encoded><![CDATA[<p>获取本周周一、周日时间，上周周一、周日时间，本月第一天，本月最后一天，上个月第一天，最后一天时间<br />
<span id="more-1081"></span></p>
<pre class="brush: php; title: ; notranslate">
//这个星期的星期一
// @$timestamp ，某个星期的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式
function this_monday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)&gt;0?86400:-/*6*86400*/518400));
		if($is_return_timestamp){
			$cache&#x5B;$id] = strtotime($monday_date);
		}else{
			$cache&#x5B;$id] = $monday_date;
		}
	}
	return $cache&#x5B;$id];

}
</pre>
<pre class="brush: php; title: ; notranslate">
//这个星期的星期天
// @$timestamp ，某个星期的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式
function this_sunday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$sunday = this_monday($timestamp) + /*6*86400*/518400;
		if($is_return_timestamp){
			$cache&#x5B;$id] = $sunday;
		}else{
			$cache&#x5B;$id] = date('Y-m-d',$sunday);
		}
	}
	return $cache&#x5B;$id];
}
</pre>
<pre class="brush: php; title: ; notranslate">
//上周一
// @$timestamp ，某个星期的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式
function last_monday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$thismonday = this_monday($timestamp) - /*7*86400*/604800;
		if($is_return_timestamp){
			$cache&#x5B;$id] = $thismonday;
		}else{
			$cache&#x5B;$id] = date('Y-m-d',$thismonday);
		}
	}
	return $cache&#x5B;$id];
}

</pre>
<pre class="brush: php; title: ; notranslate">
//上个星期天
// @$timestamp ，某个星期的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式
function last_sunday($timestamp=0,$is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$thissunday = this_sunday($timestamp) - /*7*86400*/604800;
		if($is_return_timestamp){
			$cache&#x5B;$id] = $thissunday;
		}else{
			$cache&#x5B;$id] = date('Y-m-d',$thissunday);
		}
	}
	return $cache&#x5B;$id];

}
</pre>
<pre class="brush: php; title: ; notranslate">
//这个月的第一天
// @$timestamp ，某个月的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式

function month_firstday($timestamp = 0, $is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),1,date('Y',$timestamp)));
		if($is_return_timestamp){
			$cache&#x5B;$id] = strtotime($firstday);
		}else{
			$cache&#x5B;$id] = $firstday;
		}
	}
	return $cache&#x5B;$id];
}
</pre>
<pre class="brush: php; title: ; notranslate">
//这个月的第一天
// @$timestamp ，某个月的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式

function month_lastday($timestamp = 0, $is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp),date('t',$timestamp),date('Y',$timestamp)));
		if($is_return_timestamp){
			$cache&#x5B;$id] = strtotime($lastday);
		}else{
			$cache&#x5B;$id] = $lastday;
		}
	}
	return $cache&#x5B;$id];
}
</pre>
<pre class="brush: php; title: ; notranslate">
//上个月的第一天
// @$timestamp ，某个月的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式

function lastmonth_firstday($timestamp = 0, $is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$firstday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1,1,date('Y',$timestamp)));
		if($is_return_timestamp){
			$cache&#x5B;$id] = strtotime($firstday);
		}else{
			$cache&#x5B;$id] = $firstday;
		}
	}
	return $cache&#x5B;$id];
}
</pre>
<pre class="brush: php; title: ; notranslate">
//上个月的第一天
// @$timestamp ，某个月的某一个时间戳，默认为当前时间
// @is_return_timestamp ,是否返回时间戳，否则返回时间格式

function lastmonth_lastday($timestamp = 0, $is_return_timestamp=true){
	static $cache ;
	$id = $timestamp.$is_return_timestamp;
	if(!isset($cache&#x5B;$id])){
		if(!$timestamp) $timestamp = time();
		$lastday = date('Y-m-d', mktime(0,0,0,date('m',$timestamp)-1, date('t',lastmonth_firstday($timestamp)),date('Y',$timestamp)));
		if($is_return_timestamp){
			$cache&#x5B;$id] = strtotime($lastday);
		}else{
			$cache&#x5B;$id] =  $lastday;
		}
	}
	return $cache&#x5B;$id];
}
</pre>
<pre class="brush: php; title: ; notranslate">
//demo...
echo '本周星期一：'.this_monday(0,false).'';
echo '本周星期天：'.this_sunday(0,false).'';
echo '上周星期一：'.last_monday(0,false).'';
echo '上周星期天：'.last_sunday(0,false).'';
echo '本月第一天：'.month_firstday(0,false).'';
echo '本月最后一天：'.month_lastday(0,false).'';
echo '上月第一天：'.lastmonth_firstday(0,false).'';
echo '上月最后一天：'.lastmonth_lastday(0,false).'';
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
