计算时间差
@param DateTime $time
@param DateTime $time0
@return TimeSpan
764533
public static function diff(DateTime $time,DateTime $time0=null)
    {
        if($time0==null){
            $time0=new DateTime();
        }
        return $time->diffFrom($time0);
    }
52940
public function time($time)
    {
        if ($time instanceof Carbon) {
            $time = $time->timestamp;
        }

        $this->timestamp = $time;

        return $this;
    }
777420
public function timespan($other = null, $timezone = null)
    {
        if (!$other instanceof DateTimeInterface) {
            $other = static::parse($other, $timezone);
        }

        return $this->diffForHumans($other, [
            'join' => ', ',
            'syntax' => CarbonInterface::DIFF_ABSOLUTE,
            'options' => CarbonInterface::NO_ZERO_DIFF,
            'parts' => -1,
        ]);
    }
215073
public static function now(?string $timezone = null): DateTime
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static(
            Date::create($year, $month, $day),
            Time::create($hour, $minute, $second),
            Timezone::create($timezone)
        );
    }
938712
public static function timestampToGmt($time = null)
    {
        $time = $time ?? time();
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($time)->modify('+2 hours');

        return $dateTime->format('d/m/Y H:i:s');
    }
379570
public function set($name, $value, $time = 3600)
    {
        return $this->getPredis()->set($name, $value, null, $time);
    }
538033
protected function getDateTimeInstance(string $time = "now", \DateTimeZone $timezone = null): DateTime
    {
        $result = new self::$_dateTimeClassName($time, $timezone);

        return $result;
    }
1344307
public static function maxOf(LocalDateTime ...$times) : LocalDateTime
    {
        if (! $times) {
            throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.');
        }

        $max = LocalDateTime::min();

        foreach ($times as $time) {
            if ($time->isAfter($max)) {
                $max = $time;
            }
        }

        return $max;
    }
1241087
public static function timeDiffSeconds(DateTime $time1, DateTime $time2)
    {
        $interval = $time1->diff($time2);

        return self::totalSeconds($interval);
    }
48389
public static function timeStamp($time)
    {
        $different = time() - $time;

        $seconds = $different;
        $minutes = round($different / 60);
        $hours = round($different / 3600);
        $days = round($different / 86400);
        $weeks = round($different / 604800);
        $months = round($different / 2419200);
        $years = round($different / 29030400);

        //Second
        if ($seconds <= 60) {
            if ($seconds == 1) {
                return "$seconds second ago";
            } else {
                return "$seconds seconds ago";
            }
        }

        //Minutes
        elseif ($minutes <= 60) {
            if ($minutes == 1) {
                return "$minutes minute ago";
            } else {
                return "$minutes minutes ago";
            }
        }

        //Hours
        elseif ($hours <= 24) {
            if ($hours == 1) {
                return "$hours hour ago";
            } else {
                return "$hours hours ago";
            }
        }

        //Days
        elseif ($days <= 7) {
            if ($days = 1) {
                return "$days day ago";
            } else {
                return "$days days ago";
            }
        }

        //Weeks
        elseif ($weeks <= 4) {
            if ($weeks == 1) {
                return "$weeks week ago";
            } else {
                return "$weeks weeks ago";
            }
        }

        //Months
        elseif ($months <= 12) {
            if ($months == 1) {
                return "$months month ago";
            } else {
                return "$months months ago";
            }
        }

        //Years
        else {
            if ($years == 1) {
                return "$years year ago";
            } else {
                return "$years years ago";
            }
        }
    }
893046
public static function maxTime($time = 600)
    {
        if (!self::isDebug()) {
            return false;
        }

        ini_set('max_execution_time', $time);
        set_time_limit($time);

        return self::i();
    }
933089
public function getTime($time = self::TIME_MODIFIED)
    {
        $result = false;
        $info = $this->getInfo();

        if(isset($info[$time])) {
            $result = new \DateTime('@'.$info[$time]);
        }

        return $result;
    }
1120273
public function getDateString(DateTime $time)
	{
		if ($this->getOption('type') === 'date')
		{
			return $time->format('Y-m-d');
		}
		else if ($this->getOption('type') === 'datetime')
		{
			return $time->format('Y-m-d H:i:s');
		}
		else
		{
			return $time->format('H:i:s');
		}
	}
1193933
public static function getMongoDate($time = null) {
        if (is_null($time)) {
            $time = floor(microtime(true) * 1000);
        }
        return new UTCDateTime($time);
    }
240157
protected function convertToDateTime( $time )
    {
        if ( $time instanceof DateTime )
        {
            return clone $time;
        }
        else if ( $time instanceof \DateTime )
        {
            return new DateTime( $time->format( \DateTime::ISO8601 ) );
        }
        else if ( is_numeric( $time ) )
        {
            return new DateTime( '@' . $time );
        }

        return new DateTime( (string) $time );
    }
202823
public function withTime(LocalTime $time) : LocalDateTime
    {
        if ($time->isEqualTo($this->time)) {
            return $this;
        }

        return new LocalDateTime($this->date, $time);
    }
136950
public static function fromDateTime(DateTime $dateTime)
    {
        $dateTime = clone $dateTime;

        return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
    }