ホームページ  >  記事  >  バックエンド開発  >  PHP 日付関数の例: 月の最後の日を取得する

PHP 日付関数の例: 月の最後の日を取得する

WBOY
WBOYオリジナル
2016-07-25 08:51:48825ブラウズ
  1. /**
  2. * 日付 - 月の最終日を取得します
  3. * @return int
  4. */
  5. public function get_lastday() {
  6. if($this->month==2) {
  7. $lastday = $this->is_leapyear($this->年) ? 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. }
コードをコピー

例、2 つの日付の差を計算する PHP 日付関数

  1. /**
  2. * php date-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. }
コードをコピー


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。