mysql time_format() 函数介绍

夏天,他把手中的魔法棒轻轻一挥,带给咱们一片充满活力的蓝色。你瞧,蓝蓝的天空飘着朵朵白云,远处,蔚蓝的大海在夏风的吹拂下,卷起层层浪花。

mysql 的 time_format 函数与 date_format() 函数的用法相似,但不同的是 time_format() 函数用于格式化时间,其使用方法参考下面的内容!

php time_format() 函数介绍

time_format():格式化指定的时间

语法:

time_format(time,format)

参数:

time:被格式化的时间

format:预定义格式化字符,只能使用时,分,秒!

预定义格式符列表:

限定符含义
%H24小时格式的小时,前导加0,例如:00,01..23
%h小时,12小时格式,带前导零,例如:01,02 … 12
%I与 %h 相同
%i分数为零,例如:00,01,… 59
%k24小时格式的小时,无前导零,例如:0,1,2 … 23
%l12小时格式的小时,无前导零,例如:0,1,2 … 12
%pAM或PM,取决于其他时间说明符
%r表示时间,12小时格式hh:mm:ss AM或PM
%S表示秒,前导零,如:00,01,… 59
%s与 %S 相同
%T表示时间,24小时格式hh:mm:ss

mysql time_format() 使用示例

示例1:输出带有 am pm 后缀的时间格式

select time_format('11:21:22','%r');
select time_format('15:21:22','%r');

mysql time_format() 函数介绍

示例2:time_format() 输出 hh:ii:ss 格式的时间

select time_format('01:21:22','%T');
select time_format('1:21:22','%T');

mysql time_format() 函数介绍

示例3:time_format() 输出 12小时与24小时格式的时间

select time_format('21:21:22','%h:%i:%s');
select time_format('21:21:22','%H:%i:%s');

mysql time_format() 函数介绍

本文mysql time_format() 函数介绍到此结束。人世间的真情就像一张大网,时刻温暖着人的心扉,就如妈妈的爱一样,永无止境。小编再次感谢大家支持!

标签: mysql 数据库