最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php&mysql 日期操作小記

 更新時間:2012年02月27日 21:34:21   作者:  
在php的很多成熟框架中,數(shù)據(jù)庫存儲時間都是用int類型而不是datetime類型的
在時間比較查詢的時候,int的效率明顯更高。祥文見http://m.fzitv.net/article/29767.htm
但是在做項目的時候或者直接在數(shù)據(jù)庫查看數(shù)據(jù)的時候,明顯這個int一看頭就大,比如我們想
要查看一個用戶的注冊時間:
select reg_time from t_xx_users where user_id=1;
這時候返回是個int值,不能直觀的看到具體的時間,所以這時候就涉及到datetime和int的轉(zhuǎn)化問題,
還有php的date和time也是要涉及到相應的轉(zhuǎn)化。本文略總結(jié)一下:
(1)php
int值:
time():是返回自從 Unix 紀元(格林威治時間 1970 年 1 月 1 日 00:00:00)到當前時間的秒數(shù)。
我們想要獲得1970 年 1 月 1 日到 2012-2-10的秒數(shù)可以通過strtotime()來實現(xiàn):即:strtotime('2012-2-10');
date值:
string date ( string format [, int timestamp] )
比如:直接date()返回的的實現(xiàn)當前的時間,當然我們可以指定的他的格式:例如date('Y-m-d',strtotime('2012-2-10'));
時間操作:
date('Y-m-d h:i:s',strtotime('+1 week'));
date('Y-m-d h:i:s',strtotime('+5 hours'));
date('Y-m-d h:i:s',strtotime('next Monday));
date('Y-m-d h:i:s',strtotime('last Sunday'));
date('Y-m-d h:i:s',strtotime('+ 1 day',12313223));!!詳見 int strtotime ( string time [, int now] )

(2)mysql:
int->datetime
select from_unixtime(int_time) from table;
datetime->int;
select unix_timestamp(date_time) from table;
時間操作:
select dayofweek('2012-2-2');返回一個星期的第幾天
select dayofmonth('2012-2-2');返回一月中的第幾天
select dayofyear('2012-2-2');返回一年中的第幾天
類似函數(shù): month() day() hour() week()......
+幾天 date_add(date,interval 2 days);
-幾天 date_sub(date,interval 2 days);
時間格式:
date_format(date,format)
select DATE_FORMAT('1997-10-04 22:23:00','%W %M %Y');
其他函數(shù):TIME_TO_SEC() SEC_TO_TIME()...

相關文章

最新評論

永清县| 沙湾县| 安岳县| 宜川县| 吴川市| 大理市| 宝清县| 常宁市| 寻乌县| 桂林市| 桓台县| 筠连县| 和平县| 彝良县| 沅陵县| 濉溪县| 景东| 白银市| 绍兴市| 孝义市| 图木舒克市| 文成县| 元江| 德令哈市| 灌阳县| 鹰潭市| 曲阳县| 济阳县| 江都市| 宜都市| 临泽县| 乡宁县| 长丰县| 孝感市| 梧州市| 手游| 石棉县| 永寿县| 东海县| 年辖:市辖区| 罗田县|