Maison  >  Article  >  développement back-end  >  php日期函数例子:获取当月最后一天

php日期函数例子:获取当月最后一天

WBOY
WBOYoriginal
2016-07-25 08:51:48825parcourir
  1. /**
  2. * 日期-获取当月最后一天
  3. * @return int
  4. */
  5. public function get_lastday() {
  6. if($this->month==2) {
  7. $lastday = $this->is_leapyear($this->year) ? 29 : 28;
  8. } elseif($this->month==4 || $this->month==6 || $this->month==9 || $this->month==11) {
  9. $lastday = 30;
  10. } else {
  11. $lastday = 31;
  12. }
  13. return $lastday;
  14. }
  15. /**
  16. * php日期-是否是闰年
  17. * @return int
  18. */
  19. public function is_leapyear($year) {
  20. return date('L', $year);
  21. }
复制代码

例子,php 日期函数之计算2个日期的差值

  1. /**
  2. * php日期-计算2个日期的差值
  3. * @return int
  4. */
  5. public function get_difference($date, $new_date) {
  6. $date = strtotime($date);
  7. $new_date = strtotime($new_date);
  8. return abs(ceil(($date - $new_date)/86400));
  9. }
复制代码


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn