PHP:如何转换时间

发布于 2024-10-02 00:53:57 字数 117 浏览 0 评论 0原文

如何用php转换时间?

原来的格式是00:02:34 min

我需要得到类似 154 的回声。谢谢。

How to convert time with php?

the original format was like 00:02:34 min.

I need to get a echo like 154. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怎樣才叫好 2024-10-09 00:53:57

试试这个:(

<?php
   date_default_timezone_set('GMT');
   $time = '00:00:34';
   list ($days, $hours, $minutes) = split(":", $time, 3);
   $timestamp = mktime ($hours+1, $minutes, 0, $days+1, 1, 1970, FALSE);
   $minutes = $timestamp / 60;
   print $minutes;
   print "\n";`

编辑:添加date_default_timezone_set

Try this:

<?php
   date_default_timezone_set('GMT');
   $time = '00:00:34';
   list ($days, $hours, $minutes) = split(":", $time, 3);
   $timestamp = mktime ($hours+1, $minutes, 0, $days+1, 1, 1970, FALSE);
   $minutes = $timestamp / 60;
   print $minutes;
   print "\n";`

(edit: date_default_timezone_set added)

迷离° 2024-10-09 00:53:57
$myTime="00:02:34 min";
$bodytag = str_replace(" min", "", $myTime);
$myTime=explode(":",$myTime);

function timeToSeconds($hours,$minutes,$seconds){
   return $seconds+($minutes*60)+($hours*3600);
}
$myTime="00:02:34 min";
$bodytag = str_replace(" min", "", $myTime);
$myTime=explode(":",$myTime);

function timeToSeconds($hours,$minutes,$seconds){
   return $seconds+($minutes*60)+($hours*3600);
}
反话 2024-10-09 00:53:57

嘿尤利奇卡,
我建议你检查 php 的 date 和手册中的 time 函数。从那里您还可以了解字符串到时间函数,例如 strtotime()mktime;

日期和时间允许您指定输出的格式和时间戳。格式代码的参考列在我上面给出的手动链接中。如果您没有时间戳,可以使用 strtotime() 创建一个。

Hey yuli chika,
I'll suggest you check out php's date and time functions in the manual. From there you can also learn about string to time functions like, well, strtotime() and mktime;

Date and time allow you to specify a format and a timestamp for output. The reference for the format codes are listed in the manual links I gave above. If you don't have a timestamp, you can use strtotime() to create one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文