<?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>最优良人 &#187; 日期函数</title>
	<atom:link href="http://www.zui88.com/view-tag/%e6%97%a5%e6%9c%9f%e5%87%bd%e6%95%b0/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zui88.com/blog</link>
	<description>中山php&#124;最优网络</description>
	<lastBuildDate>Mon, 13 May 2013 04:56:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>php时间日期函数date,getdate,strtotime,strftime,strptime,time,mktime,microtime汇总对比</title>
		<link>http://www.zui88.com/blog/view-145.html</link>
		<comments>http://www.zui88.com/blog/view-145.html#comments</comments>
		<pubDate>Fri, 19 Aug 2011 08:56:51 +0000</pubDate>
		<dc:creator>lin</dc:creator>
				<category><![CDATA[后端程序]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[日期函数]]></category>

		<guid isPermaLink="false">http://www.zui88.com/blog/?p=145</guid>
		<description><![CDATA[date — 格式化一个本地时间／日期（把时间戳变成文本格式） string date ( string $format [, int $timestamp ] ) timestamp 是可选的，默认值为 time()。 $today = date("H:i:s"); // 17:16:17 getdate — 取得日期／时间信息（把时间戳的信息存到数组） array getdate ([ int $timestamp ] ) &#60;?php $today = getdate(); print_r($today); ?&#62; 返回 Array ( [seconds] =&#62; 40 [minutes] =&#62; 58 [hours] =&#62; 21 [mday] =&#62; 17 [wday] =&#62; 2 [...]]]></description>
			<content:encoded><![CDATA[<p>date — 格式化一个本地时间／日期（把时间戳变成文本格式）<br />
string date ( string $format [, int $timestamp ] )<br />
timestamp 是可选的，默认值为 time()。<br />
$today = date("H:i:s");                         // 17:16:17</p>
<p>getdate — 取得日期／时间信息（把时间戳的信息存到数组）<br />
array getdate ([ int $timestamp ] )<br />
&lt;?php<br />
$today = getdate();<br />
print_r($today);<br />
?&gt;<br />
返回<br />
Array<br />
(<br />
[seconds] =&gt; 40<br />
[minutes] =&gt; 58<br />
[hours]   =&gt; 21<br />
[mday]    =&gt; 17<br />
[wday]    =&gt; 2<br />
[mon]     =&gt; 6<br />
[year]    =&gt; 2003<br />
[yday]    =&gt; 167<br />
[weekday] =&gt; Tuesday<br />
[month]   =&gt; June<br />
[0]       =&gt; 1055901520<br />
)</p>
<p>strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳 （把文本格式变成时间戳）<br />
int strtotime ( string $time [, int $now ] )<br />
函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳（自 January 1 1970 00:00:00 GMT 起的秒数），其值相对于 now 参数给出的时间，如果没有提供此参数则用系统当前时间。<br />
&lt;?php<br />
echo strtotime("2011-9-9"), "\n";<br />
echo strtotime("now"), "\n";<br />
echo strtotime("10 September 2000"), "\n";<br />
echo strtotime("+1 day"), "\n";<br />
echo strtotime("+1 week"), "\n";<br />
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";<br />
echo strtotime("next Thursday"), "\n";<br />
echo strtotime("last Monday"), "\n";<br />
?&gt;<br />
strtotime的第一个参数可以是我们常见的英文时间格式，比如"2008-8-20"或"10 September 2000"等等。也可以是以参数now为基准的时间描述，比如"+1 day"等等。</p>
<p>下面是后一种方式的可使用参数清单，其中"当前时间"是指strtotime第二个参数now的值，默认为当前时间。</p>
<p>1. 月,日英文名及其常用缩写清单:<br />
january,february,march,april,may,june,july,august,september,sept,october,november,december,<br />
sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,thurs,friday,saturday</p>
<p>2. 时间参数和祥细描述:<br />
am: the time is before noon　上午<br />
pm: the time is noon or later　下午<br />
year: one year; for example, "next year"　年，比如"next year"代表明年<br />
month: one month; for example, "last month"　月，比如"last month"代表上一月<br />
fortnight: two weeks; for example, "a fortnight ago"　两周，比如"a fortnight ago"代表两周前<br />
week: one week　周<br />
day: a day　天<br />
hour: an hour　小时<br />
minute: a minute　分钟<br />
min: same as minute　同"minute"<br />
second: a second 秒<br />
sec: same as second　同"second"</p>
<p>3.相关和顺序说明:<br />
+n/-n:以当前时间算，加个减指定的时间，比如"+1 hour"是指当前时间加一小时<br />
ago:time relative to now; such as "24 hours ago" 　以当前时间往前算，比如"24 hours ago"代表"24小时前"<br />
tomorrow: 24 hours later than the current date and time　以当前时间（包括日期和时间）为标准，明天同一时间<br />
yesterday: 24 hours earlier than the current date and time　以当前时间（包括日期和时间）为标准，昨天同一时间<br />
today: the current date and time　当前时间（包括日期和时间）<br />
now: the current date and time　当前时间（包括日期和时间）<br />
last: modifier meaning "the preceding"; for example, "last tuesday"　代表"上一个"，比如"last tuesday"代表"上周二同一时间"<br />
this: the given time during the current day or the next occurrence of the given time; for example, "this 7am" gives the timestamp for 07:00 on the current day, while "this week" gives the timestamp for one week from the current time　当天的指定时间或下面一个时间段的时间戳，比如"this 7am"给出当天7:00的时间戳，而"this week"给出的是从当前时间开始的一整周的时间戳，也就是当前时间（经本人测试：strtotime('this week')=strtotime('now')）;<br />
next: modifier meaning the current time value of the subject plus one; for example, "next hour"　当前时间加上指定的时间，比如"next hour"是指当前时间加上一小时，即加3600</p>
<p>first: ordinal modifier, esp. for months; for example, "May first" (actually, it's just the same as next)<br />
third: see first (note that there is no "second" for ordinality, since that would conflict with the second time value)<br />
fourth: see first<br />
fifth: see first<br />
sixth: see first<br />
seventh: see first<br />
eighth: see first<br />
ninth: see first<br />
tenth: see first<br />
eleventh: see first<br />
twelfth: see first</p>
<p>4. 时区描述:<br />
gmt: Greenwich Mean Time<br />
ut: Coordinated Universal Time<br />
utc: same as ut<br />
wet: Western European Time<br />
bst: British Summer Time<br />
wat: West Africa Time<br />
at: Azores Time<br />
ast: Atlantic Standard Time<br />
adt: Atlantic Daylight Time<br />
est: Eastern Standard Time<br />
edt: Eastern Daylight Time<br />
cst: Central Standard Time<br />
cdt: Central Daylight Time<br />
mst: Mountain Standard Time<br />
mdt: Mountain Daylight Time<br />
pst: Pacific Standard Time<br />
pdt: Pacific Daylight Time<br />
yst: Yukon Standard Time<br />
ydt: Yukon Daylight Time<br />
hst: Hawaii Standard Time<br />
hdt: Hawaii Daylight Time<br />
cat: Central Alaska Time<br />
akst: Alaska Standard Time<br />
akdt: Alaska Daylight Time<br />
ahst: Alaska-Hawaii Standard Time<br />
nt: Nome Time<br />
idlw: International Date Line West<br />
cet: Central European Time<br />
met: Middle European Time<br />
mewt: Middle European Winter Time<br />
mest: Middle European Summer Time<br />
mesz: Middle European Summer Time<br />
swt: Swedish Winter Time<br />
sst: Swedish Summer Time<br />
fwt: French Winter Time<br />
fst: French Summer Time<br />
eet: Eastern Europe Time, USSR Zone 1<br />
bt: Baghdad Time, USSR Zone 2<br />
zp4: USSR Zone 3<br />
zp5: USSR Zone 4<br />
zp6: USSR Zone 5<br />
wast: West Australian Standard Time<br />
wadt: West Australian Daylight Time<br />
cct: China Coast Time, USSR Zone 7<br />
jst: Japan Standard Time, USSR Zone 8<br />
east: Eastern Australian Standard Time<br />
eadt: Eastern Australian Daylight Time<br />
gst: Guam Standard Time, USSR Zone 9<br />
nzt: New Zealand Time<br />
nzst: New Zealand Standard Time<br />
nzdt: New Zealand Daylight Time<br />
idle: International Date Line East</p>
<p>strftime — 根据区域设置格式化本地时间／日期 （把时间戳变成文本格式）<br />
string strftime ( string $format [, int $timestamp ] )<br />
strftime()工作的方式和date()没有什么不同，除了特殊格式化字符的前面必须添加一个百分号%。<br />
strftime()有两个好处。第一个好处是如果你使用setlocale()函数，你可以通过strftime得到相应语言的月份的名称。另外的一个好处是你可以将特别的日期和时间的格式化字符包含在你的字符串中。这同时也意味着无论你是否要学习date()函数的所有特殊格式化字符，你都必须学习一整套完全不同的格式化字符。<br />
一般phper用date会比较顺手吧。</p>
<p>strptime — 解析由 strftime() 生成的日期／时间 （把文本格式的日期信息存到数组）<br />
array strptime ( string $date , string $format )<br />
类似于date函数的getdate<br />
&lt;?php<br />
$format = '%d/%m/%Y %H:%M:%S';<br />
$strf = strftime($format);</p>
<p>echo "$strf\n";</p>
<p>print_r(strptime($strf, $format));<br />
?&gt;<br />
输出<br />
03/10/2004 15:54:19</p>
<p>Array<br />
(<br />
[tm_sec] =&gt; 19<br />
[tm_min] =&gt; 54<br />
[tm_hour] =&gt; 15<br />
[tm_mday] =&gt; 3<br />
[tm_mon] =&gt; 9<br />
[tm_year] =&gt; 104<br />
[tm_wday] =&gt; 0<br />
[tm_yday] =&gt; 276<br />
[unparsed] =&gt;<br />
)</p>
<p>time — 返回当前的 Unix 时间戳<br />
int time ( void )</p>
<p>mktime — 取得一个日期的 Unix 时间戳<br />
int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] )<br />
参数可以从右向左省略，任何省略的参数会被设置成本地日期和时间的当前值，参数全部为空则与time()相同</p>
<p>microtime — 返回当前 Unix 时间戳和微秒数<br />
microtime() 当前 Unix 时间戳以及微秒数。本函数仅在支持 gettimeofday() 系统调用的操作系统下可用。<br />
如果调用时不带可选参数，本函数以 "msec sec" 的格式返回一个字符串，其中 sec 是自 Unix 纪元（0:00:00 January 1, 1970 GMT）起到现在的秒数，msec 是微秒部分。字符串的两部分都是以秒为单位返回的。<br />
如果给出了 get_as_float 参数并且其值等价于 TRUE，microtime() 将返回一个浮点数。默认为false<br />
&lt;?php<br />
echo microtime(true);//1313743963.77<br />
echo microtime(false);//0.10190200 1313744036<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zui88.com/blog/view-145.html/feed</wfw:commentRss>
		<slash:comments>379</slash:comments>
		</item>
	</channel>
</rss>
