Heim  >  Artikel  >  Backend-Entwicklung  >  php日期函数例子:获取当月最后一天

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

WBOY
WBOYOriginal
2016-07-25 08:51:48825Durchsuche
  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. }
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn