当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTime::diff方法代码示例

本文整理汇总了PHP中DateTime::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::diff方法的具体用法?PHP DateTime::diff怎么用?PHP DateTime::diff使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


在下文中一共展示了DateTime::diff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: outputDuration

 public function outputDuration()
 {
     $from = new DateTime($this->getFromDate());
     $to = new DateTime($this->getToDate());
     $output = 'Stored for ';
     $days = (int) $from->diff($to)->format('%d');
     $months = (int) $from->diff($to)->format('%m');
     $daysString = $days . ' day';
     if ($days > 1) {
         $daysString .= 's';
     }
     $monthsString = $months . ' month';
     if ($months > 1) {
         $monthsString .= 's';
     }
     if ($days > 0 && $months > 0) {
         return 'Request for ' . $monthsString . ', ' . $daysString;
     } else {
         if ($days > 0) {
             return 'Request for ' . $daysString;
         } else {
             if ($months > 0) {
                 return 'Request for ' . $monthsString;
             }
         }
     }
 }
开发者ID:increpare,项目名称:hackspace-foundation-sites,代码行数:27,代码来源:project.php

示例2: getDuration

 /**
  * @see PeriodableInterface::getDuration
  */
 public function getDuration()
 {
     if (!$this->startDate instanceof \DateTime || !$this->endDate instanceof \DateTime) {
         return null;
     }
     return $this->startDate->diff($this->endDate);
 }
开发者ID:VincentBee,项目名称:vbee_site,代码行数:10,代码来源:PeriodableTrait.php

示例3: showAction

 /**
  * Show the user
  */
 public function showAction()
 {
     $user = $this->getUser();
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException('Este usuario no tiene acceso a esta seccion.');
     }
     $fecha = new \DateTime('now');
     $datos = array('Estado' => 'Sin relación a paciente o personal.');
     if ($this->getUser()->getIdTipoUsuario()->getNombre() == 'Paciente') {
         $repository = $this->getDoctrine()->getRepository('AsiClinicaBundle:Paciente');
         $paciente = $repository->findOneByIdusuario($this->getUser()->getId());
         if (isset($paciente)) {
             $edad = $fecha->diff($paciente->getFechanacimiento())->y;
             $datos = array('Nombre' => $paciente->getNombres() . ' ' . $paciente->getApellidos(), 'Género' => $paciente->getGenero(), 'Edad' => $edad, 'Teléfono' => $paciente->getTelefono(), 'Móvil' => $paciente->getMovil(), 'Lugar de nacimiento' => $paciente->getLugarnacimiento(), 'Dirección' => $paciente->getDireccion(), 'Departamento' => $paciente->getIdmunicipio()->getIddepartamento()->getNombre(), 'Municipio' => $paciente->getIdmunicipio()->getNombre(), 'Fecha de registro' => $paciente->getFechacreacion()->format('Y-m-d'));
         }
     } else {
         $repository = $this->getDoctrine()->getRepository('AsiClinicaBundle:Personal');
         $personal = $repository->findOneByIdusuario($this->getUser()->getId());
         if (isset($personal)) {
             $edad = $fecha->diff($personal->getFechanacimiento())->y;
             $datos = array('Nombre' => $personal->getNombres() . ' ' . $personal->getApellidos(), 'Edad' => $edad, 'Teléfono' => $personal->getTelefono(), 'Móvil' => $personal->getMovil(), 'DUI' => $personal->getDui(), 'Dirección' => $personal->getDireccion(), 'Departamento' => $personal->getIdmunicipio()->getIddepartamento()->getNombre(), 'Municipio' => $personal->getIdmunicipio()->getNombre());
         }
     }
     return $this->render('FOSUserBundle:Profile:show.html.twig', array('user' => $user, 'datos' => $datos));
 }
开发者ID:sanborino,项目名称:clinica,代码行数:28,代码来源:ProfileController.php

示例4: sejam

 private function sejam($waktu, $dimunculkan)
 {
     $today = new DateTime();
     $selisih = $today->diff($waktu)->i;
     echo "selisih menit: {$selisih}<br>";
     return $waktu > $today && $waktu->format("Y-m-d") == $today->format("Y-m-d") && $today->diff($waktu)->h == 0 && (0 <= $selisih && $selisih <= 59) && ($dimunculkan & 1 << 0) == 0;
 }
开发者ID:coderhutan,项目名称:notifier,代码行数:7,代码来源:sms.php

示例5: getInterval

 /**
  * 
  * @return \DateInterval
  */
 private function getInterval()
 {
     if (is_null($this->interval)) {
         $this->interval = $this->currentTime->diff($this->comparatorTime);
     }
     return $this->interval;
 }
开发者ID:webignition,项目名称:readable-duration,代码行数:11,代码来源:ReadableDuration.php

示例6: array

            default:
                $format = '%y ' . Tools::declension($date_start->diff($now)->format('%y'), array('год', 'года', 'лет')) . ' %m ' . Tools::declension($date_start->diff($now)->format('%m'), array('месяц', 'месяца', 'месяцев')) . ' %d ' . Tools::declension($date_start->diff($now)->format('%d'), array('день', 'дня', 'дней'));
                break;
        }
        return $this->Text . ' ' . $date_start->diff($now)->format($format);
    }
    /**
	* Return slider position
开发者ID:AleksandrChukhray,项目名称:good_deals,代码行数:8,代码来源:Ruler.php

示例7: fetch_report_data

 public function fetch_report_data()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $month = FormLib::get('month', date('n'));
     $year = FormLib::get('year', date('Y'));
     $end_of_last_month = mktime(0, 0, 0, $month, 0, $year);
     $ts = mktime(0, 0, 0, $month, 1, $year);
     $end_of_next_month = mktime(0, 0, 0, $month, date('t', $ts), $year);
     $end_last_dt = new DateTime(date('Y-m-d', $end_of_last_month));
     $end_next_dt = new DateTime(date('Y-m-d', $end_of_next_month));
     $loans = new GumLoanAccountsModel($dbc);
     $data = array();
     foreach ($loans->find('loanDate') as $loan) {
         $record = array($loan->accountNumber(), number_format($loan->principal(), 2), number_format($loan->interestRate() * 100, 2) . '%', $loan->termInMonths(), date('Y-m-d', strtotime($loan->loanDate())));
         $loanDT = new DateTime(date('Y-m-d', strtotime($loan->loanDate())));
         $days1 = $loanDT->diff($end_last_dt)->format('%r%a');
         $days2 = $loanDT->diff($end_next_dt)->format('%r%a');
         $bal_before = $loan->principal() * pow(1.0 + $loan->interestRate(), $days1 / 365.25);
         if ($days1 < 0) {
             $bal_before = $loan->principal();
         }
         $bal_after = $loan->principal() * pow(1.0 + $loan->interestRate(), $days2 / 365.25);
         if ($days2 < 0) {
             $bal_after = $loan->principal();
         }
         $record[] = number_format($bal_before, 2);
         $record[] = number_format($bal_after, 2);
         $record[] = number_format($bal_after - $bal_before, 2);
         $data[] = $record;
     }
     return $data;
 }
开发者ID:phpsmith,项目名称:IS4C,代码行数:33,代码来源:GumInterestReport.php

示例8: __invoke

 /**
  * Calculate the years, days and hours between two supplied dates.
  * @param \DateTime $startDate
  * @param \DateTime $endDate
  * @return string
  */
 public function __invoke(\DateTime $startDate, \DateTime $endDate)
 {
     /**
      * Check to ensure that valid dates are entered.
      */
     if ($endDate <= $startDate) {
         throw new \InvalidArgumentException("Please ensure that the end date is less than the start date.");
     }
     /**
      * Start by calculating the complete different between the two dates.
      */
     $interval = $startDate->diff($endDate);
     /**
      * Extract the number of years only and create a new DateInterval based on this.
      */
     $numberOfYears = $interval->y;
     $yearInterval = new \DateInterval('P' . $interval->y . 'Y');
     /**
      * Using the original start date, add the new, whole-year interval.
      * We're not using DateTimeImmutable so the original object will be updated.
      */
     $startDate->add($yearInterval);
     /**
      * Now we diff the modified start date with the end date again. This will give
      * a timestamp of < 1 year.
      */
     $subYearInterval = $startDate->diff($endDate);
     /**
      * Output the number of years, followed by the number of days in the foreshortened
      * interval and finally, the number of hours.
      *
      * This could be improved using localisation and pluralisation.
      */
     return $subYearInterval->format($numberOfYears . ' years, %a day(s) and %h hour(s)');
 }
开发者ID:pawcode,项目名称:UserAgeInHours,代码行数:41,代码来源:IntervalYearsDaysHours.php

示例9: getDateInterval

 /**
  * Gets the interval between the two dates
  *
  * @return DateInterval
  */
 public function getDateInterval()
 {
     if (!$this->from && !$this->to) {
         return null;
     }
     return $this->from->diff($this->to);
 }
开发者ID:arbmainassara,项目名称:AvocodeFormExtensionsBundle,代码行数:12,代码来源:DateRange.php

示例10: make

 public function make($date, array $to_date = [])
 {
     if (is_array($date)) {
         $dt = \DateTime::createFromFormat($date[1] ?: $this->format_in, $date[0]);
     } else {
         $dt = \DateTime::createFromFormat($this->format_in, $date);
     }
     $cmp_date = $dt->format($this->format_out);
     if (!empty($to_date) && is_array($to_date)) {
         $today_dt = \DateTime::createFromFormat($to_date[1] ?: $this->format_in, $to_date[0]);
     } else {
         $today_dt = new \DateTime();
     }
     $today = $today_dt->format($this->format_out);
     $yesterday = $today_dt->modify('-1 day')->format($this->format_out);
     $diff_days = $today_dt->diff($dt)->format('%a') + 1;
     $diff_years = $today_dt->diff($dt)->format('%y');
     if ($cmp_date == $today) {
         return 'сегодня';
     } else {
         if ($cmp_date == $yesterday) {
             return 'вчера';
         } else {
             if ($diff_years >= 1) {
                 return $this->prefix . 'более ' . $diff_years . ' ' . self::getDecline($diff_years, 'года', 'лет', 'лет') . $this->postfix;
             } else {
                 if ($diff_days >= 2) {
                     return $this->prefix . $diff_days . ' ' . self::getDecline($diff_days, 'день', 'дня', 'дней') . $this->postfix;
                 }
             }
         }
     }
     return null;
 }
开发者ID:heartshare,项目名称:yii2-daysago,代码行数:34,代码来源:DaysAgo.php

示例11: getAge

 private function getAge($upload_date)
 {
     $ts = upload_date;
     $date = new DateTime("@{$ts}");
     $from = new DateTime($date->format('Y-m-d'));
     $to = new DateTime('today');
     $year = $from->diff($to)->y;
     $months = $from->diff($to)->m;
     $days = $from->diff($to)->days;
     $hours = $from->diff($to)->h;
     $minutes = $from->diff($to)->i;
     $age = 'Fresh';
     if ($year > 0) {
         $age = $year == 1 ? $year . " year" : $year . " years";
     } else {
         if ($months > 0) {
             $age = $months == 1 ? $months . " month" : $months . " months";
         } else {
             if ($days > 0) {
                 $age = $days == 1 ? $days . " day" : $days . " days";
             } else {
                 if ($hours > 0) {
                     $age = $hours == 1 ? $hours . " hour" : $hours . " hours";
                 } else {
                     if ($minutes > 0) {
                         $age = $minutes == 1 ? $minutes . " minute" : $minutes . " minutes";
                     }
                 }
             }
         }
     }
     return $age;
 }
开发者ID:jakop345,项目名称:strike-search,代码行数:33,代码来源:TorrentSearch.php

示例12: get_months

function get_months($date)
{
    $d1 = new DateTime($date);
    $current_time = date("Y-m-d");
    $d2 = new DateTime($current_time);
    //var_dump($d1->diff($d2)->m); // int(4)
    return $d1->diff($d2)->m + $d1->diff($d2)->y * 12;
}
开发者ID:enockoloo6,项目名称:hre2,代码行数:8,代码来源:user_helper.php

示例13:

 function it_checks_hourly()
 {
     $now = new \DateTime();
     $diff = $now->diff(new \DateTime('-3 minute'));
     $this->hourly($diff)->shouldBe(true);
     $diff = $now->diff(new \DateTime('-64 minutes'));
     $this->hourly($diff)->shouldBe(false);
     $diff = $now->diff(new \DateTime('-2 hours'));
     $this->hourly($diff)->shouldBe(false);
 }
开发者ID:basuritas-php,项目名称:php-datetime-ago,代码行数:10,代码来源:DateTimeAgoSpec.php

示例14: isItTime

 /**
  * @return bool
  */
 private static function isItTime()
 {
     $dateLastConfiguration = new \DateTime(\RedDevil\Config\RoutesConfig::$dateOfLastCheck);
     $now = new \DateTime();
     $hoursPassed = $now->diff($dateLastConfiguration)->days * 24 + $now->diff($dateLastConfiguration)->h;
     if ($hoursPassed > 1) {
         return true;
     }
     return false;
 }
开发者ID:straho99,项目名称:ConferenceManager-Project,代码行数:13,代码来源:RouteConfigurator.php

示例15: __toString

 /**
  *
  * @return string l'intitulé du voyage et les dates
  */
 public function __toString()
 {
     $interval = $this->date_debut->diff($this->date_fin);
     if ($interval->days < 1) {
         $str_date = "le " . $this->date_debut->format('d/m/Y') . ", " . $this->date_debut->format('H:i') . " / " . $this->date_fin->format('H:i');
     } else {
         $str_date = "du " . $this->date_debut->format('d/m/Y') . " à " . $this->date_debut->format('H:i') . " au " . $this->date_fin->format('d/m/Y') . " à " . $this->date_fin->format('H:i');
     }
     return $this->libelle . ' (' . $str_date . ')';
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:14,代码来源:Voyage.php


注:本文中的DateTime::diff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。