Create Variable in PHP Equal to Current Time Minus One Hour

前端 未结 9 1299
青春惊慌失措
青春惊慌失措 2020-12-11 15:12

In PHP, how could I create a variable called $livetime that equals the current time minus 1 hour?

相关标签:
9条回答
  • 2020-12-11 15:41
    $livetime = time() - 3600; // 3600 seconds in 1 hour : 60 seconds (1 min) * 60 (minutes in hour)
    

    See time PHP function for more information.

    0 讨论(0)
  • 2020-12-11 15:43

    Another way - without all the math and, in my opinion, reads better.

    $hour_ago = strtotime('-1 hour');
    
    0 讨论(0)
  • Here you go:

    <?php
    
    $now = time();
    echo strftime("%c",$now) . "\n";
    $livetime = $now-3600;
    echo strftime("%c",$livetime) . "\n";
    ?>
    
    0 讨论(0)
提交回复
热议问题