PHP convert datetime to seconds

前端 未结 4 1687
南方客
南方客 2020-12-18 21:31

I have a datetime value in mysql \'2010-12-08 16:12:12\'
that I\'d like to get the seconds to that date using PHP,
so basically a PHP

相关标签:
4条回答
  • 2020-12-18 21:39
    <?php
    
    $date1 = new DateTime("2010-12-08 16:12:12");
    $now = new DateTime();
    
    $difference_in_seconds = $date1->format('U') - $now->format('U');
    

    ->format('U') turns it into a unix timestamp.

    0 讨论(0)
  • 2020-12-18 21:59

    huh ? these function are from mysql ...

    For PHP, you replace it using strtotime

    $diff = strtotime('2010-12-08 16:12:12')-time();
    

    details : http://php.net/manual/en/function.strtotime.php

    0 讨论(0)
  • 2020-12-18 21:59

    Use mktime()

    http://php.net/manual/en/function.mktime.php

    0 讨论(0)
  • 2020-12-18 22:01

    try

    $time_diff = time() - strtotime('2010-12-08 16:12:12');
    
    0 讨论(0)
提交回复
热议问题