日期—时间戳转换(PHP,Mysql)

mysql

1、时间戳转换为日期
from_unixtime(时间戳字段,format) 
例:
from_unixtime(ctime,"%Y-%m-%d")


2、日期转换为时间戳
unix_timestamp(date)      
例:
mysql> SELECT UNIX_TIMESTAMP() ; (当前时间) 
->1249524739 
mysql> SELECT UNIX_TIMESTAMP('2009-08-06') ; 
->1249488000 


3、日期字段格式化
date_format(日期字段,format)
例:
select date_format(日期字段,’%Y-%m-%d’) as ‘日期’ from test


PHP

1、时间戳转换成日期
date(format,时间戳)
例如:
         $time = time();//时间戳,当前时间
         $nowtime = date('Y-m-d H:i:s',$time);//生成带格式的日期
2、日期转换成时间戳
例如:
         $oldtime = '2010-11-10 22:19:21';  
         $catime = strtotime($oldtime);//日期转换为时间戳  
  strtotime("2013/3/23");
  strtotime("2013-4-23 00:00:32");

你可能感兴趣的:(mysql,PHP,时间戳,日期)