在php中获取视频持续时间的格式化时间
这应该很容易...
我的持续时间以秒为单位, 我想以小时:分钟:秒的格式输出它
当我尝试...
// video duration is 1560 seconds
<?=date("h:i:s",$video->duration)?>
...它输出 07:26:00 而不是 00:26:00。所以我认为这是一个时区问题。
在我的应用程序开始时,我像这样设置时区
date_default_timezone_set('America/Montreal');
现在我想如果我将时区更改为 GMT,我会得到正常值,但我不想每次我想要一个简单的持续时间时都这样做(并重新设置时区到美国/蒙特利尔)
我有什么选择?
This should be easy...
I have a duration in seconds,
I want to output it in hours:minutes:seconds format
When I try...
// video duration is 1560 seconds
<?=date("h:i:s",$video->duration)?>
...it outputs 07:26:00 instead of 00:26:00. So I figure it's a time zone issue.
At the beginning of my application I set the timezone like this
date_default_timezone_set('America/Montreal');
Now I guess I would get my normal value if I change the timezone to GMT but I don't want to do that each time I want a simple duration (and re-set the timezone to America/Montreal)
What are my options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
date 用于获取人类可读的 unix 时间戳格式,因此这不是您所需要的。换句话说,该函数用于显示日期(例如 12.12.2012),而不是视频的持续时间,
因为您可以创建一个从总秒数开始的函数,并执行类似的操作,
也许您需要调整此值位,因为我没有测试它。如果视频很短,还有一些测试可以跳过几小时或几分钟
date is used to get a human readable format for an unix timestamp, so it's not what you need. In other words that function is used to show a date (like 12.12.2012) and not the duration of your video
for that you can create a function that starts from the total number of seconds and does something like
maybe you need to adjust this a bit, as I did not test it. also some tests to skip hours or minutes if the video is short
这是一个老问题,但我想我可以为此提供答案:
This is an old question but I thought I can provide an answer for this: