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


PHP date_diff函数代码示例

本文整理汇总了PHP中date_diff函数的典型用法代码示例。如果您正苦于以下问题:PHP date_diff函数的具体用法?PHP date_diff怎么用?PHP date_diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get_state

 function get_state()
 {
     $this->db->select('User_Status as Sp, User_Current_Time as CT');
     $this->db->from('user');
     $this->db->where('User_ID', $this->get_data('id'));
     $query = $this->db->get();
     if ($query->num_rows() > 0) {
         $status = $query->row_array(1);
         $date = mdate('%Y-%m-%d %H:%i:%s', now('Asia/Manila'));
         $diff = date_diff(new DateTime($status['CT']), new DateTime($date));
         if (!$this->input->cookie("DTMSUserData")) {
             echo "no_cookie";
         } else {
             if ($this->input->cookie("DTMSUserData")) {
                 $data = json_decode($this->encrypt->decode(get_cookie("DTMSUserData")), TRUE);
                 if ($status['Sp'] == 1) {
                     echo "suspended";
                 } elseif ($status['Sp'] == 0) {
                     echo "activated";
                 } else {
                     echo $data["state"];
                 }
             }
         }
     }
 }
开发者ID:johnjoshualipio,项目名称:lcwd_dtms,代码行数:26,代码来源:User_model.php

示例2: time_ago

 public static function time_ago($timestamp)
 {
     $now = new DateTime('now');
     $from = new DateTime();
     $from->setTimestamp($timestamp);
     $diff = date_diff($now, $from);
     if ($diff->y > 0) {
         $message = $diff->y . ' year' . ($diff->y > 1 ? 's' : '');
     } else {
         if ($diff->m > 0) {
             $message = $diff->m . ' month' . ($diff->m > 1 ? 's' : '');
         } else {
             if ($diff->d > 0) {
                 $message = $diff->d . ' day' . ($diff->d > 1 ? 's' : '');
             } else {
                 if ($diff->h > 0) {
                     $message = $diff->h . ' hour' . ($diff->h > 1 ? 's' : '');
                 } else {
                     if ($diff->i > 0) {
                         $message = $diff->i . ' minute' . ($diff->i > 1 ? 's' : '');
                     } else {
                         if ($diff->s > 0) {
                             $message = $diff->s . ' second' . ($diff->s > 1 ? 's' : '');
                         } else {
                             $message = 'a moment';
                         }
                     }
                 }
             }
         }
     }
     return $message . ' ago';
 }
开发者ID:danisdead,项目名称:gastrointernacional,代码行数:33,代码来源:UBUtil.php

示例3: deactivate_expired_listing

 public function deactivate_expired_listing()
 {
     $this->load->model('properties_listing_model');
     $this->load->model('users_model');
     $activated_lists = $this->properties_listing_model->find_all(array('activate' => 1));
     if (!empty($activated_lists)) {
         foreach ($activated_lists as $activated_list) {
             # last query here
             $current_date = new DateTime();
             $activate_date = new DateTime($activated_list->activate_time);
             $diff = date_diff($activate_date, $current_date, TRUE);
             $total_diff = $diff->format('%y') * 12 + $diff->format('%m');
             $expire_duration = $activated_list->deactivate_duration;
             if ((int) $total_diff >= $expire_duration) {
                 $activated_list->activate = 0;
                 $activated_list->save();
                 $user = $this->users_model->find_one(array('id' => $activated_list->user_id));
                 echo $activated_list->ref_tag . " is deactivated \n";
                 $data['ref_tag'] = $activated_list->ref_tag;
                 $this->_send_email('deactivation', $user['email'], $data);
                 echo "Notification sent to " . $user['email'];
             }
         }
     }
 }
开发者ID:ressphere,项目名称:cb_iloveproperty,代码行数:25,代码来源:garbage_collector.php

示例4: duration

function duration(&$hrs) {
  $time = ceil(time()/3600)*3600;
  $now = new DateTime("@$time");
  $poh = new DateTime("@".($time-$hrs*3600));
  $age = date_diff($poh,$now);
  $hrs = "$hrs (".($age->y?"{$age->y}y, ":"").($age->m?"{$age->m}m, ":"").($age->d?"{$age->d}d, ":"")."{$age->h}h)";
}
开发者ID:bergware,项目名称:dynamix-v6.1,代码行数:7,代码来源:SmartInfo.php

示例5: age

 public function age()
 {
     $bd = $this->patient->getOriginal('dateOfBirth');
     $diagDate = $this->schedule->getOriginal('diagDate');
     $age = date_diff(date_create($bd), date_create($diagDate))->y;
     return $age . ' ปี';
 }
开发者ID:princemaw,项目名称:iHospital,代码行数:7,代码来源:appointment.php

示例6: getLeaveDays

 public static function getLeaveDays($start_date, $end_date)
 {
     $start = new DateTime($start_date);
     $end = new DateTime($end_date);
     $diff = date_diff($start, $end);
     return $diff->d;
 }
开发者ID:kenkode,项目名称:xaraerp,代码行数:7,代码来源:Leaveapplication.php

示例7: niceDate

 public function niceDate($date, $preciseDate = false)
 {
     $dates = explode(' ', $date);
     $jours = explode('-', $dates[0]);
     $heures = explode(':', $dates[1]);
     if ($date > date('Y-m-d H:i:s')) {
         $date_a = new DateTime(date('Y-m-d H:i:s'));
         $date_b = new DateTime($date);
         $interval = date_diff($date_a, $date_b);
         $intervalFormat = explode(':', $interval->format('%d:%h:%I'));
         $str = $intervalFormat[0] > 0 ? $intervalFormat[0] . ' ' . __('day') . ($intervalFormat[0] > 1 ? 's' : '') . ' ' : '';
         $str .= $intervalFormat[1] > 0 ? $intervalFormat[1] . 'h' : '';
         $str .= $intervalFormat[0] == 0 && $intervalFormat[2] > 0 ? $intervalFormat[2] : '';
         if ($preciseDate && $dates[0] == date("Y-m-d")) {
             $str .= ' (' . __('Today at') . ' ' . $heures[0] . 'h' . $heures[1] . ')';
         } elseif ($preciseDate) {
             $str .= ' (' . $date_b->format('d/m/Y') . ')';
         }
         return __('in') . ' ' . $str;
     } elseif ($dates[0] == date("Y-m-d")) {
         $text = __('Today at');
         return $text . ' ' . $heures[0] . 'h' . $heures[1];
     } elseif ($dates[0] == date('Y-m-d', time() - 3600 * 24)) {
         $text = __('Yesterday at');
         return $text . ' ' . $heures[0] . 'h' . $heures[1];
     } else {
         $wording = $this->jour_semaine_court[date('w', mktime(0, 0, 0, $jours[1], $jours[2], $jours[0]))] . ' ';
         $wording .= $jours[2] . ' ' . strtolower($this->month[intval($jours[1])]) . ' ' . $jours[0];
         return $wording;
     }
 }
开发者ID:Chaoslan,项目名称:mushraider,代码行数:31,代码来源:ToolsHelper.php

示例8: verbatim_date

function verbatim_date($date)
{
    $dt = new DateTime($date);
    $dt = new DateTime($dt->format('Y-m-d'));
    //only date we need
    $dt_now = new DateTime("now");
    $dt_now = new DateTime($dt_now->format('Y-m-d'));
    //only date we need
    if (!function_exists('date_diff')) {
        require_once ROOT_PATH . 'includes/date_diff_legacy.php';
        $interval = date_diff($dt, $dt_now);
    } else {
        $interval = date_diff($dt, $dt_now);
    }
    if ($interval->y == 0 && $interval->m == 0 && $interval->d == 0) {
        //		return array("Today","0x649812");
        return array($dt->format('d M'), "0x649812");
    } else {
        if ($interval->y == 0 && $interval->m == 0 && $interval->d == 1) {
            //		return array("Yesterday","0x000000");
            return array($dt->format('d M'), "0x000000");
        } else {
            if ($dt->format('Y') == $dt_now->format('Y')) {
                return array($dt->format('d M'), "0x000000");
            } else {
                return array($dt->format('d M Y'), "0x000000");
            }
        }
    }
}
开发者ID:rogergraves,项目名称:emotethis,代码行数:30,代码来源:DateFormat.php

示例9: userViewAction

 public function userViewAction($id)
 {
     $user = $this->getDoctrine()->getManager()->getRepository('BFUserBundle:User')->find($id);
     $numberfollows = count($listFollows = $this->getDoctrine()->getManager()->getRepository('BFSiteBundle:Follow')->findByFollowing($user));
     $numbervideos = count($listVideos = $this->getDoctrine()->getManager()->getRepository('BFSiteBundle:Video')->listVideos($user));
     $duelwins = $user->getDuelWins();
     $allChallenges = $this->getDoctrine()->getManager()->getRepository('BFSiteBundle:Challenge')->findall();
     $userChallenges = array();
     foreach ($allChallenges as $challenge) {
         //get the vidéos for every challenge
         $listChallengeVideos = $this->getDoctrine()->getManager()->getRepository('BFSiteBundle:Video')->videoForChallenge($challenge, $user);
         if (!empty($listChallengeVideos)) {
             array_push($userChallenges, $listChallengeVideos);
         }
     }
     $listDuels = $user->getDuels();
     //retrieving the service
     $info = $this->container->get('bf_site.rankinfo');
     $rankinfo = $info->rankInfo($user);
     $duelRankInfo = $info->duelRankInfo($user);
     //calculating the age of the user.
     $interval = date_diff(new \Datetime(), $user->getBirthday());
     $age = $interval->y;
     //here we create an array with all the informations for the profileTop
     $profileTopInfo = array('followscount' => $numberfollows, 'videoscount' => $numbervideos, 'age' => $age, 'duelwins' => $duelwins);
     $lists = array('listVideos' => $listVideos, 'listFollows' => $listFollows, 'listDuels' => $listDuels, 'userChallenges' => $userChallenges);
     $rank = array('rankinfo' => $rankinfo, 'duelrankinfo' => $duelRankInfo);
     return $this->render('BFAdminBundle:User:view.html.twig', array('lists' => $lists, 'user' => $user, 'rank' => $rank, 'profiletop' => $profileTopInfo));
 }
开发者ID:jojotjebaby,项目名称:Bestfootball,代码行数:29,代码来源:UserController.php

示例10: timeDifferance

function timeDifferance($dateTime1, $dateTime2)
{
    $call_start = new DateTime($dateTime1);
    $call_end = new DateTime($dateTime2);
    $interval = date_diff($call_start, $call_end);
    return $interval->format('%h hour %i min %s sec');
}
开发者ID:dasatti,项目名称:dashboard,代码行数:7,代码来源:sitefunction.php

示例11: dateDifference

function dateDifference($date_1, $date_2, $differenceFormat = '%a')
{
    $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);
    $interval = date_diff($datetime1, $datetime2);
    return $interval->format($differenceFormat);
}
开发者ID:AbrahamOdoi,项目名称:zoom,代码行数:7,代码来源:functions_bkp.php

示例12: diff

 public static function diff($from, $to)
 {
     $datetime1 = date_create($from);
     $datetime2 = date_create($to);
     $interval = date_diff($datetime1, $datetime2);
     return $interval->format('%R%a days');
 }
开发者ID:madiarsa,项目名称:DVD-Rental,代码行数:7,代码来源:DateFormat.php

示例13: exp_encode

 static function exp_encode($days)
 {
     $datetime1 = date_create('1970-01-01');
     $datetime2 = date_create($days);
     $interval = date_diff($datetime1, $datetime2);
     return (int) $interval->format('%a');
 }
开发者ID:karepwes,项目名称:OcsPanels,代码行数:7,代码来源:webmin.php

示例14: compareDate

 public static function compareDate($one, $two)
 {
     $datetime1 = date_create($one);
     $datetime2 = date_create($two);
     $interval = date_diff($datetime1, $datetime2);
     return $interval->days;
 }
开发者ID:guiles00,项目名称:acfj,代码行数:7,代码来源:Utils.php

示例15: createAction

 /**
  * Creates a new Events entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Events();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     // On récupère la date de début et de fin d'évènement afin de les comparer
     $startEvent = $form->getViewData()->getStart();
     $startEvent_string = strftime("%A %#d %B %Y à %k:%M", $startEvent->getTimestamp());
     $endEvent = $form->getViewData()->getEnd();
     if ($form->isValid()) {
         // On détermine la différence entre les heures et les minutes
         $diffTime_min = date_diff($startEvent, $endEvent)->i;
         $diffTime_hour = date_diff($startEvent, $endEvent)->h;
         // Si la durée de l'event est inferieur à une heure, alors, on le met à une heure automatiquement
         if ($diffTime_min <= 59 && $diffTime_hour == 0) {
             date_sub($endEvent, date_interval_create_from_date_string($diffTime_min . 'min'));
             $entity->setEnd($endEvent->modify('+1 hours'));
         }
         $em = $this->getDoctrine()->getManager();
         $user = $this->container->get('security.token_storage')->getToken()->getUser();
         // On se protège de la faille XSS
         $entity->setTitre(htmlspecialchars($form->getViewData()->getTitre()));
         $entity->setResume(htmlspecialchars($form->getViewData()->getResume()));
         $entity->setDateAjout(new \DateTime());
         $entity->setIdUser($user);
         $this->colorEvent($entity);
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('agenda_homepage'));
     }
     return $this->render('AgendaBundle:Events:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'startEvent' => $startEvent_string));
 }
开发者ID:WildCodeSchool,项目名称:partnet,代码行数:36,代码来源:EventsController.php


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