当前位置:Gxlcms > 数据库问题 > mysql 时间戳与日期格式的相互转换

mysql 时间戳与日期格式的相互转换

时间:2021-07-01 10:21:17 帮助过:27人阅读

 
  1. select FROM_UNIXTIME(1156219870);  

     输出:2006-08-22 12:11:10

 

 

2、日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()

 

[sql] view plain copy  
  1.  Select UNIX_TIMESTAMP(‘2006-11-04 12:23:00‘);  

 

 




[sql] view plain copy
 


  1. 输出:1162614180  
[sql] view plain copy  
  1. Select UNIX_TIMESTAMP(NOW());  
[sql] view plain copy  
  1.    
[sql] view plain copy  
  1. 输出当前时间戳  

 

 

例:mysql查询当天的记录数:

 

[sql] view plain copy  
  1. $sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),’%Y-%m-%d’) = DATE_FORMAT(NOW(),’%Y-%m-%d’) order by id desc”;  



 

PHP方式转换:

UNIX时间戳转换为日期用函数: date()

 

date(‘Y-m-d H:i:s‘, 1156219870);

 

日期转换为UNIX时间戳用函数:strtotime()

     strtotime(‘2010-03-24 08:15:42‘);

mysql 时间戳与日期格式的相互转换

标签:amp   转换   blank   strtotime   格式   link   toc   sql   log   

人气教程排行