<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[实践OK]Mysql用timestamp存时间建立索引用PHP去查询时间比较,在PHP中怎么将date()函数转换为unix时间戳？]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 31 Mar 2010 07:41:12 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	在项目中经常会在某个时候停止某个功能，这儿写一下作为备份：<br/><br/>int mktime&nbsp;&nbsp;([&nbsp;&nbsp;int $hour = date(&quot;H&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $minute = date(&quot;i&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $second = date(&quot;s&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $month = date(&quot;n&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $day = date(&quot;j&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $year = date(&quot;Y&quot;)&nbsp;&nbsp;[,&nbsp;&nbsp;int $is_dst = -1&nbsp;&nbsp;]]]]]]] )<br/><br/> Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.<br/><br/>Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time. <br/><br/><div class="code"><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nowDate=mktime(date(&#039;H&#039;),date(&#039;i&#039;),date(&#039;s&#039;),date(&#039;m&#039;),date(&#039;d&#039;),date(&#039;Y&#039;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$forbidden_end = mktime(23,59,59,3,31,2010);//结束时间<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($nowDate &gt;= $forbidden_end)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$content = json_encode ( array (&quot;code&quot; =&gt; -1, &quot;message&quot; =&gt; &quot;温馨提示：**活动已经结束，谢谢你的参与!&quot;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $content;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;</div><br/><br/><br/><br/>一）date函数是将timestamp 转化成特定格式日期的.<br/>二）需要获取时间戳 用time函数可以获得当前时间的timestamp<br/>用strtotime(格式)可以获取指定时间的时间戳:<br/>日期转换为UNIX时间戳用函数：strtotime() <br/>一般形式：strtotime(&#039;2010-03-24 08:15:42&#039;)； <br/><br/><br/><br/>关于Mysql时间字段格式如何选择，TIMESTAMP，DATETIME，INT？以下摘自：http://segmentfault.com/q/1010000000121702<br/>首先 DATETIM和TIMESTAMP类型所占的存储空间不同，前者8个字节，后者4个字节，这样造成的后果是两者能表示的时间范围不同。前者范围为1000-01-01 00:00:00 ~ 9999-12-31 23:59:59，后者范围为1970-01-01 08:00:01到2038-01-19 11:14:07。所以可以看到TIMESTAMP支持的范围比DATATIME要小,容易出现超出的情况.<br/>其次，TIMESTAMP类型在默认情况下，insert、update 数据时，TIMESTAMP列会自动以当前时间（CURRENT_TIMESTAMP）填充/更新。<br/>第三，TIMESTAMP比较受时区timezone的影响以及MYSQL版本和服务器的SQL MODE的影响<br/>所以一般来说，我比较倾向选择DATETIME，至于你说到索引的问题，选择DATETIME作为索引，如果碰到大量数据查询慢的情况，也可以分区表解决。<br/>______________________________________________________________________________________________________________________________________________________________________<br/>其实速度上差别不是很大，你可以自己做做测试就知道了。内部存储都是整数，只不过datetime和timestamp会仅仅在显示的时候，显示为人能读的日期（当然存储空间有点区别，整形和timestamp都是4字节，datetime是8字节），做索引也应该没什么区别，这个不敢确定，如果有请指正我……<br/>另外datetime和timestamp相对于int来说也有一个小小的好处，就是对于时间类型来说，可以有一系列的时间函数可以用<br/>这几个类型的选择还是看你的需求。<br/>我用timestamp比较多，对于记录日志什么的需求，timestamp绝对够用了，除非你保证说你的程序能一直用到2038年，就算如此也可以用迁移程序处理……<br/>如果需求是允许用户保存一些超过timestamp能保存的时间（@QingchaoWu 已经给出了timestamp的范围）比如说todo list什么的，允许用户计划38年以后的事情，那就用datetime好了。<br/>______________________________________________________________________________________________________________________________________________________________________<br/>还是喜欢INT存时间戳。占用资源少，查询速度快。条件范围搜索使用between没什么问题。查询条件自由拼接。用int还是比较好的。使用其他字段类型貌似MySQL内部还会进行一次转换，时间格式的比对不是特别青睐。<br/>一般我使用INT格式，灵活些<br/>如果你要在表示时间字段上建立索引，那么使用INT索引效率要高<br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]Mysql用timestamp存时间建立索引用PHP去查询时间比较,在PHP中怎么将date()函数转换为unix时间戳？]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>