简体   繁体   English

在cakePHP / PHP中获取一小时和几分钟的时间戳

[英]Get an hour and minutes of a timestamp in cakePHP/ PHP

Sounds like a silly queston, but I need a quick answer and could not find it. 听起来像一个愚蠢的任务,但我需要一个快速的答案,找不到它。

I have a timestamp: '15:40:00' , and I need to create two separate variables: hours and minutes. 我有一个时间戳: '15:40:00' ,我需要创建两个单独的变量:小时和分钟。

Much much appreciated. 非常感谢。

list()explode()在这里工作得很好。

list($hours, $minutes, $seconds) = explode(':', '15:40:00');

You can also use one function sscanf() (variables will be integer type) : 你也可以使用一个函数sscanf() (变量将是integer类型)

sscanf('15:40:00', '%d:%d:%d', $hours, $minutes, $seconds);

demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM