Calculate the time difference(in seconds).
@param string|integer $datetime1
@param string|integer $datetime2
@return integer Positive integer if $datetime1 is later than $datetime2, and vise versa.
191991
public function getDatetimeOffset($datetime1, $datetime2 = null)
    {
        if ($datetime2 === null) {
            if ($this->timeType == static::$timeTypeLocal) {
                $datetime2 = $this->currentDatetime();
            } elseif ($this->timeType == static::$timeTypeUtc) {
                $datetime2 = $this->currentUtcDatetime();
            }
        }
        if ($this->timeFormat == static::$timeFormatDatetime) {
            $datetime1 = strtotime($datetime1);
            $datetime2 = strtotime($datetime2);
        }
        return $datetime1 - $datetime2;
    }
740587
public static function splitDate($dateTime, $type = 'int')
    {
        $t  = explode(' ', $dateTime);
        $t1 = explode('-', $t[0]);
        $t2 = explode(':', $t[1]);
        if ($type == 'int') {
            $x['date']   = (int)$t1[2];
            $x['month']  = (int)$t1[1];
            $x['year']   = (int)$t1[0];
            $x['hour']   = (int)$t2[0];
            $x['minute'] = (int)$t2[1];
            $x['second'] = (int)$t2[2];
        } else { // string
            $x['date']   = $t1[2];
            $x['month']  = $t1[1];
            $x['year']   = $t1[0];
            $x['hour']   = $t2[0];
            $x['minute'] = $t2[1];
            $x['second'] = $t2[2];
        }

        return $x;
    }
647761
public static function compareTimeWithoutDate($date1, $date2)
    {
        $date1 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date1->format('H:i:s'));
        $date2 = DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 ' . $date2->format('H:i:s'));
        if ($date1 == $date2) {
            return 0;
        }
        if ($date1 < $date2) {
            return -1;
        }

        return 1;
    }
1194638
public function withSecond(int $second) : ZonedDateTime
    {
        return ZonedDateTime::of($this->localDateTime->withSecond($second), $this->timeZone);
    }
1239511
public function closest($date1, $date2)
    {
        return $this->diffInRealMicroseconds($date1) < $this->diffInRealMicroseconds($date2) ? $date1 : $date2;
    }
1157549
private static long dateTimeDifference(final Temporal d1, final Temporal d2) {
      return ChronoUnit.SECONDS.between(d1, d2);
  }
941609
public static function fromNative(DateTimeInterface $dateTime): Time
    {
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static($hour, $minute, $second);
    }
466220
public function intervaloEntreDatasBr($data1, $data2)
    {
        $data1 = $this->converterParaDateTime($data1, $this->FORMATO_DATA_BR);
        $data2 = $this->converterParaDateTime($data2, $this->FORMATO_DATA_BR);

        if (!$data1 || !$data2) {
            return false;
        }

        return date_diff($data1, $data2);
    }
1124170
public function dateDiff($time1, $time2 = null)
    {
        if (is_null($time2)) {
            $time2 = Mage::getModel('core/date')->date();
        }
        $time1 = strtotime($time1);
        $time2 = strtotime($time2);
        return $time2 - $time1;
    }
63349
private function validateDateTime($datetime)
    {
        if (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', $datetime, $parts) == true) {
            $time = gmmktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]);

            $input_dt = new \DateTime($datetime, new \DateTimeZone('GMT0'));
            $input_time = $input_dt->getTimestamp();
            if ($input_time === false) return false;

            return $input_time == $time;
        } else {
            return false;
        }
    }
181909
public function convertToUnixTimestamp($dateTime)
    {
        // ignore fractional second
        if (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:|\.\d+)(Z|[+-]\d{2}:\d{2})$/', $dateTime, $matches)) {
            $timestamp = gmmktime(
                $matches[4], $matches[5], $matches[6], // hours, minutes, seconds
                $matches[2], $matches[3], $matches[1]  // month, day, year
            );

            // local offset (timezone)
            if ($matches[7] !== 'Z') {
                preg_match('/^([+-])(\d{2}):(\d{2})$/', $matches[7], $matches);

                $offset = ($matches[1] === '-' ? -1 : 1) * ($matches[2] * 60 + $matches[3]) * 60;
                $timestamp -= $offset;
            }
        }

        return $timestamp;
    }
1006386
public static function dateDiff($Date1, $Date2)
    {
        $DateList1=explode("-", $Date1);
        $DateList2=explode("-", $Date2);
        $d1=mktime(0, 0, 0, $DateList1[1], $DateList1[2], $DateList1[0]);
        $d2=mktime(0, 0, 0, $DateList2[1], $DateList2[2], $DateList2[0]);
        $Days=round(($d1-$d2)/3600/24);
        return $Days;
    }
1050693
public static function difference(int $stamp1, int $stamp2 = null): int
    {
        if (!is_int($stamp2)) {
            $stamp2 = time();
        }

        return $stamp2 > $stamp1 ? $stamp2 - $stamp1 : $stamp1 - $stamp2;
    }
593137
public static function fromNativeDateTime(\DateTime $time)
    {
        $hour   = \intval($time->format('G'));
        $minute = \intval($time->format('i'));
        $second = \intval($time->format('s'));

        return static::fromNative($hour, $minute, $second);
    }
1313308
public static function get_DateTime( &$dateTime )
    {
        if( $dateTime instanceof DateTime ) {
            return $dateTime;
        }
        return !is_null($dateTime)
            ? new DateTime( $dateTime )
            : null
            ;
    }
686406
public static function getDuration(DateTime $a, DateTime $b) {
        static::compareZone($a, $b);
        return $b->getTimestamp() - $a->getTimestamp();
    }
663866
public static function timeDifferent($time1, $time2)
    {
        $intTime1 = $this->unixTime($time1);
        $intTime2 = $this->unixTime($time2);
        $timeDiff = $intTime2 - $intTime1;

        return $timeDiff;
    }