dtyw10299 2016-09-22 05:42
浏览 34
已采纳

PHP将字符串转换为持续时间

Using PHP, MySQLi.

I am selecting a string from a MySQL database and saving it to a variable called $queryTime, I'd like to modify how this string is displayed on screen. When I print_r($queryTime); I see;

01:25:24

When I var_dump($queryTime) I see;

string(8) "01:25:24"

Is there any way I can display the string in a time duration format - something like;

1 hour, 25 minutes, 24 seconds

Presumably because the database field is stored as a varchar and not a time-stamp things are more complicated? Unfortunately I don't have access to modify the database.

Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • dongou0524 2016-09-22 05:50
    关注

    You could simple work on that string, if the format is always the same:

    $queryTime = '01:25:24';
    
    $parts = explode(':', $queryTime);
    $parts[0] .= ' hours';
    $parts[1] .= ' minutes';
    $parts[2] .= ' seconds';
    
    //01 hours, 25 minutes, 24 seconds
    echo implode(', ', $parts);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部