代码之家  ›  专栏  ›  技术社区  ›  steven

如果有时间,我怎么能在一个月前找到时间呢

  •  5
  • steven  · 技术社区  · 16 年前

    如果有时间,我怎么能在一个月前找到时间呢?

    6 回复  |  直到 7 年前
        1
  •  16
  •   Galen    16 年前
    strtotime( '-1 month', $timestamp );
    

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

        2
  •  3
  •   justinl    16 年前

    在PHP中,您可以使用strtotime(“-1个月”)。在这里查看文档: http://ca3.php.net/strtotime

        3
  •  2
  •   TheMohanAhuja    10 年前

    我们可以通过使用PHP的现代日期处理来实现这一点。这将需要php 5.2或更高版本。

    // say its "2015-11-17 03:27:22"
    $dtTm = new DateTime('-1 MONTH', new DateTimeZone('America/Los_Angeles')); // first argument uses strtotime parsing
    echo $dtTm->format('Y-m-d H:i:s'); // "2015-10-17 03:27:22"
    

    希望这能为这个问题添加更多信息。

        4
  •  1
  •   Kirill V. Lyadvinsky    16 年前
    <?php
    
    $date = new DateTime("18-July-2008 16:30:30");
    echo $date->format("d-m-Y H:i:s").'<br />';
    
    date_sub($date, new DateInterval("P1M"));
    echo '<br />'.$date->format("d-m-Y").' : 1 Month';
    
    ?> 
    
        5
  •  0
  •   Sadee    7 年前

    PHP 5.2=& lt;

    $date = new DateTime(); // Return Datetime object for current time
    $date->modify('-1 month'); // Modify to deduct a month (Also can use '+1 day', '-2 day', ..etc)
    echo $date->format('Y-m-d'); // To set the format 
    

    裁判: http://php.net/manual/en/datetime.modify.php

        6
  •  0
  •   Davit Huroyan    7 年前

    此代码用于在30天前1个月

    $date = "2016-03-31";
    
    $days = date("t", strtotime($date));
    
    echo  date("Y-m-d", strtotime( "-$days days", strtotime($date) ));
    
    推荐文章