【问题标题】:PHP get time different in stringPHP在字符串中获取时间不同
【发布时间】:2014-12-01 12:18:34
【问题描述】:

我有一个时间字符串,第一个用户的最后一次登录:'2014.12.01, 12:25' 以及如何计算与现在不同的时间?例如另一个用户看到第一个用户的最后一次登录

At 12:30 and it says 5 minute ago.
Or at 13:23 says 48 minute ago.
Or at 14:24 says 1 hour ago.
Or one day later, it says 1 day ago.

【问题讨论】:

标签: php string time formatting


【解决方案1】:

您可以尝试以下方法:

$to_time = strtotime("2014-12-01 12:25:00");
$from_time = strtotime("2014-12-01 12:25:00");

$minutes = round(abs($to_time - $from_time) / 60,2);
$seconds = abs($to_time - $from_time) % 60;

echo "$minutes minute, $seconds seconds";

已经在以下链接回答了:

"Calculate time different in minute and second"

希望对你有帮助

【讨论】:

    【解决方案2】:
    $first_user_time = '2014-12-01 12:30:00';
    $curnt_user_time = '2014-12-01 12:40:00';
    
    $diff = date('h:i:s', strtotime($first_user_time)-strtotime($curnt_user_time))
    
    echo $diff;
    
    //it will give diff in hour : min : seconds
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多