How do I add 24 hours to a unix timestamp in php?

前端 未结 7 662
南方客
南方客 2020-11-30 19:23

I would like to add 24 hours to the timestamp for now. How do I find the unix timestamp number for 24 hours so I can add it to the timestamp for right now?

I also w

相关标签:
7条回答
  • 2020-11-30 19:49

    A Unix timestamp is simply the number of seconds since January the first 1970, so to add 24 hours to a Unix timestamp we just add the number of seconds in 24 hours. (24 * 60 *60)

    time() + 24*60*60;
    
    0 讨论(0)
  • 2020-11-30 19:51

    Add 24*3600 which is the number of seconds in 24Hours

    0 讨论(0)
  • 2020-11-30 19:51

    You could use the DateTime class as well:

    $timestamp = mktime(15, 30, 00, 3, 28, 2015);
    
    $d = new DateTime();
    $d->setTimestamp($timestamp);
    

    Add a Period of 1 Day:

    $d->add(new DateInterval('P1D'));
    echo $d->format('c');
    

    See DateInterval for more details.

    0 讨论(0)
  • 2020-11-30 19:52

    As you have said if you want to add 24 hours to the timestamp for right now then simply you can do:

     <?php echo strtotime('+1 day'); ?>
    

    Above code will add 1 day or 24 hours to your current timestamp.

    in place of +1 day you can take whatever you want, As php manual says strtotime can Parse about any English textual datetime description into a Unix timestamp.

    examples from the manual are as below:

    <?php
         echo strtotime("now"), "\n";
         echo strtotime("10 September 2000"), "\n";
         echo strtotime("+1 day"), "\n";
         echo strtotime("+1 week"), "\n";
         echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
         echo strtotime("next Thursday"), "\n";
         echo strtotime("last Monday"), "\n";
    ?>
    
    0 讨论(0)
  • 2020-11-30 19:54

    Unix timestamp is in seconds, so simply add the corresponding number of seconds to the timestamp:

    $timeInFuture = time() + (60 * 60 * 24);
    
    0 讨论(0)
  • 2020-11-30 19:55
    $time = date("H:i", strtotime($today . " +5 hours +30 minutes"));
    //+5 hours +30 minutes     Time Zone +5:30 (Asia/Kolkata)
    
    0 讨论(0)
提交回复
热议问题