123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- if (!defined('IS_INITPHP')) exit('Access Denied!');
- class dateInit {
-
- private $year, $month, $day;
-
-
- public function set_date($date = '') {
- if ($date !== '') {
- list($year, $month, $day) = explode('-', $date);
- $this->set_year($year);
- $this->set_month($month);
- $this->set_day($day);
- } else {
- $this->set_year(date('Y'));
- $this->set_month(date('m'));
- $this->set_day(date('d'));
- }
- }
-
-
- public function add_day($day_num = 1) {
- $day_num = (int) $day_num;
- $day_num = $day_num * 86400;
- $time = $this->get_time() + $day_num;
- $this->set_year(date('Y', $time));
- $this->set_month(date('m', $time));
- $this->set_day(date('d', $time));
- return $this->get_date();
- }
-
- public function get_lastday() {
- if($this->month==2) {
- $lastday = $this->is_leapyear($this->year) ? 29 : 28;
- } elseif($this->month==4 || $this->month==6 || $this->month==9 || $this->month==11) {
- $lastday = 30;
- } else {
- $lastday = 31;
- }
- return $lastday;
- }
-
-
- public function get_week() {
- return date('w', $this->get_time());
- }
-
-
- public function is_leapyear($year) {
- return date('L', $year);
- }
-
-
- public function get_date() {
- return $this->year.'-'.$this->month.'-'.$this->day;
- }
-
-
- public function get_birthday() {
- return $this->month.'-'.$this->day;
- }
-
- public function get_time() {
- return strtotime($this->get_date().' 23:59:59');
- }
-
-
- public function get_difference($date, $new_date) {
- $date = strtotime($date);
- $new_date = strtotime($new_date);
- return abs(ceil(($date - $new_date)/86400));
- }
-
-
- public static function getChinaWeek($week = null) {
- $week = $week ? $week : (int) date('w', time());
- $weekArr = array("星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
- return $weekArr[$week];
- }
-
-
- private function set_year($year) {
- $year = (int) $year;
- $this->year = ($year <= 2100 && $year >= 1970) ? $year : date('Y');
- }
-
-
- private function set_month($month) {
- $month = ltrim((int) $month, '0');
- $this->month = ($month < 13 && $month > 0) ? $month : date('m');
- }
-
-
- private function set_day($day) {
- $day = ltrim((int) $day, '0');
- $this->day = ($this->year && $this->month && checkdate($this->month, $day, $this->year)) ? $day : date('d');
- }
-
- }
|