mysql time conversion

-- 秒	%S、%s	两位数字形式的秒( 00,01, ..., 59)
-- 分	%I、%i	两位数字形式的分( 00,01, ..., 59)
-- 小时 	
-- %H	24小时制,两位数形式小时(00,01, ...,23)
-- %h	12小时制,两位数形式小时(00,01, ...,12)
-- %k	24小时制,数形式小时(0,1, ...,23)
-- %l	12小时制,数形式小时(0,1, ...,12)
-- %T	24小时制,时间形式(HH:mm:ss)
-- %r	12小时制,时间形式(hh:mm:ss AM 或 PM)
-- %p 	AM上午或PM下午 

-- 查询当前时间
select now();

-- 时间转字符串
select date_format(now(), '%Y-%m-%d');

-- 时间转时间戳
select unix_timestamp(now());
 
-- 字符串转时间
select str_to_date('2016-01-02 12:02:33', '%Y-%m-%d %H:%i:%s');  

-- 字符串转时间戳
select unix_timestamp('2016-01-02');

-- 时间戳转时间
select from_unixtime(1451997924);

-- 时间戳转字符串
select from_unixtime(1451997924,'%Y-%d');  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325261496&siteId=291194637