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


PHP DateUtil类代码示例

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


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

示例1: initWxTokenToDB

 /**
  * save token to db
  */
 public static function initWxTokenToDB()
 {
     global $db;
     $url = wxTokenUrl() . "&appid=" . appid() . "&secret=" . secret();
     // 请求微信token
     //LogUtil::logs("initWxTokenToDB tokenurl====>".$url, getLogFile('/business.log'));
     $arr = RequestUtil::httpGet($url);
     $newToken = $arr['access_token'];
     //LogUtil::logs("initWxTokenToDB newToken====>".$newToken, getLogFile('/business.log'));
     // 请求微信ticket
     $newTicket = self::initTicket($newToken);
     $updatetime = DateUtil::getCurrentTime();
     // 加锁文件
     if (file_exists($lockfile)) {
         //LogUtil::logs("initWxTokenToDB ====> file in writing, only can read\r\n", getLogFile('/business.log'));
         exit;
     }
     // save or update;
     $db->exec("INSERT INTO wx_token(id, token, updatetime, ticket) \r\n\t\tvalues(1, '{$newToken}','{$updatetime}','{$newTicket}') \r\n\t\tON DUPLICATE KEY UPDATE token='{$newToken}', updatetime='{$updatetime}', ticket='{$newTicket}'");
     // 关闭锁文件
     fclose($lockTemp);
     // 删除锁文件
     unlink($lockfile);
     return $newToken;
 }
开发者ID:jurimengs,项目名称:bangsm,代码行数:28,代码来源:WxUtil.php

示例2: getContent

 public function getContent($args)
 {
     switch ($args['pluginid']) {
         case 1:
             //$uid = $args['uid'];
             // Get matching news stories published since last newsletter
             // No selection on categories made !!
             $items = ModUtil::apiFunc('News', 'user', 'getall',
                             array('numitems' => $this->getVar('itemsperpage'),
                                 'status' => 0,
                                 'from' => DateUtil::getDatetime($args['last']),
                                 'filterbydate' => true));
             if ($items != false) {
                 if ($args['contenttype'] == 't') {
                     $counter = 0;
                     $output.="\n";
                     foreach ($items as $item) {
                         $counter++;
                         $output .= $counter . '. ' . $item['title'] . " (" . $this->__f('by %1$s on %2$s', array($item['contributor'], DateUtil::formatDatetime($item['from'], 'datebrief'))) . ")\n";
                     }
                 } else {
                     $render = Zikula_View::getInstance('News');
                     $render->assign('readperm', SecurityUtil::checkPermission('News::', "::", ACCESS_READ));
                     $render->assign('articles', $items);
                     $output = $render->fetch('mailz/listarticles.tpl');
                 }
             } else {
                 $output = $this->__f('No News publisher articles since last newsletter on %s.', DateUtil::formatDatetime($args['last'], 'datebrief')) . "\n";
             }
             return $output;
     }
     return '';
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:33,代码来源:Mailz.php

示例3: handleForm

 public function handleForm($context, $action)
 {
     if ($action == "createAd") {
         if (isset($_POST['start']) && $_POST['start'] != "" && (isset($_POST['size']) && $_POST['size'] != "") && (isset($_POST['name']) && $_POST['name'] != "") && (isset($_POST['url']) && $_POST['url'] != "")) {
             $start = $_POST['start'];
             $end = $_POST['end'];
             $dayOfWeek = date("D", strtotime($start));
             $splitStart = explode("/", $start);
             $mysqlStart = $splitStart[2] . "-" . $splitStart[0] . "-" . $splitStart[1];
             $splitEnd = explode("/", $end);
             $mysqlEnd = $splitEnd[2] . "-" . $splitEnd[0] . "-" . $splitEnd[1];
             if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
                 $filename = $this->saveSampleImage($context, $_FILES['image'], SessionUtil::getUsername());
                 if ($filename != "") {
                     WebAdDao::createWebAd($_POST['name'], DateUtil::findPreviousMonday($mysqlStart), $_POST['size'], $filename, $_POST['url'], $mysqlStart, $mysqlEnd);
                 } else {
                     $context->addError("Error Uploading File, Please Try Again.");
                 }
             } else {
                 $context->addError("No File Uploaded.");
             }
         } else {
             $context->addError("Required Field Left Blank.");
         }
     } else {
         $context->addError("Incorrect Action.");
     }
 }
开发者ID:ramielrowe,项目名称:Web-Ads,代码行数:28,代码来源:CreateAdHandler.php

示例4: index

 public function index()
 {
     $error = '';
     if (RequestUtil::isPost()) {
         $validate = new ValidateUtil();
         $validate->required('user_name');
         $validate->required('password');
         $validate->required('verify_code');
         $params = RequestUtil::postParams();
         if ($params['verify_code'] != UserUtil::getVerifyCode()) {
             $error = '验证码错误!';
         } else {
             if ($validate->run()) {
                 $userModel = new UserModel();
                 $params['password'] = $userModel->encodePassword($params['password']);
                 $where = array('user_name' => $params['user_name'], 'password' => $params['password']);
                 $user = (new CurdUtil($userModel))->readOne($where, 'user_id desc', '*, user_type+0 as type');
                 if (!$user) {
                     $error = '登录失败,账号或者密码错误,请重试!';
                 } else {
                     (new CurdUtil($userModel))->update($where, array('last_login_time' => DateUtil::now()));
                     UserUtil::saveUser($user);
                     if (UserUtil::isAdmin()) {
                         ResponseUtil::redirect(UrlUtil::createBackendUrl('project/index'));
                     } else {
                         ResponseUtil::redirect(UrlUtil::createBackendUrl('beautician/index'));
                     }
                 }
             }
         }
     }
     $this->load->view('backend/login', array('error' => $error));
 }
开发者ID:guohao214,项目名称:xinya,代码行数:33,代码来源:Login.php

示例5: findPreviousMonday

 public static function findPreviousMonday($mysqlDate)
 {
     $time = strtotime(DateUtil::mysqlToPhpDate($mysqlDate));
     $day = date("D", $time);
     if ($day == "Mon") {
         return date(DateUtil::MYSQLDATE_FORMAT, $time);
     } else {
         if ($day == "Tue") {
             return date(DateUtil::MYSQLDATE_FORMAT, $time - DateUtil::DAY_IN_SECONDS);
         } else {
             if ($day == "Wed") {
                 return date(DateUtil::MYSQLDATE_FORMAT, $time - 2 * DateUtil::DAY_IN_SECONDS);
             } else {
                 if ($day == "Thu") {
                     return date(DateUtil::MYSQLDATE_FORMAT, $time - 3 * DateUtil::DAY_IN_SECONDS);
                 } else {
                     if ($day == "Fri") {
                         return date(DateUtil::MYSQLDATE_FORMAT, $time - 4 * DateUtil::DAY_IN_SECONDS);
                     } else {
                         if ($day == "Sat") {
                             return date(DateUtil::MYSQLDATE_FORMAT, $time - 5 * DateUtil::DAY_IN_SECONDS);
                         } else {
                             if ($day == "Sun") {
                                 return date(DateUtil::MYSQLDATE_FORMAT, $time - 6 * DateUtil::DAY_IN_SECONDS);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:ramielrowe,项目名称:Reservation-System-V2,代码行数:32,代码来源:DateUtil.php

示例6: synchronizedUserInfo

 /**
  * 将用户信息同步到数据库
  */
 public function synchronizedUserInfo($userInfo, $Event)
 {
     global $db;
     $openid = $userInfo["openid"];
     $subscribe = $userInfo["subscribe"];
     $currtime = DateUtil::getCurrentTime();
     $sql = "";
     if ($Event == "subscribe") {
         LogUtil::logs("TypeEvent synchronizedUserInfo insert=====> ", getLogFile("/business.log"));
         $nickname = $userInfo["nickname"];
         $nickname = base64_encode($nickname);
         //$nickname = str_replace("🌻", "*", $nickname);
         $sex = $userInfo["sex"];
         $headimgurl = $userInfo["headimgurl"];
         $sql = $sql . ", nickname='{$nickname}', sex='{$sex}'";
         LogUtil::logs("TypeEvent.php synchronizedUserInfo  :nickname ====>" . $nickname, getLogFile('/business.log'));
         // 关注的情况有关注和重新关注,所以使用on duplicate的方法
         $sql = "INSERT INTO `wx_user_info` (openid, nickname, sex, subscribe, subscribe_time, headimgurl) \r\n\t\t\tVALUES ('{$openid}', '{$nickname}', '{$sex}', '{$subscribe}', '{$currtime}', '{$headimgurl}') \r\n\t\t\tON DUPLICATE KEY UPDATE subscribe='{$subscribe}', nickname='{$nickname}', subscribe_time='{$currtime}', headimgurl='{$headimgurl}'";
     } else {
         // 取消关注
         LogUtil::logs("TypeEvent synchronizedUserInfo update=====> ", getLogFile("/business.log"));
         $sql = "update `wx_user_info` set subscribe_time='{$currtime}', subscribe='{$subscribe}' where openid = '{$openid}' ";
     }
     $db->exec($sql);
 }
开发者ID:jurimengs,项目名称:bangsm,代码行数:28,代码来源:TypeEvent.php

示例7: diff

 /** Diff two date objects. Only full units are returned */
 public static function diff(TimeInterval $interval, Date $date1, Date $date2) : int
 {
     if ($date1->getOffsetInSeconds() != $date2->getOffsetInSeconds()) {
         // Convert date2 to same timezone as date1. To work around PHP bug #45038,
         // not just take the timezone of date1, but construct a new one which will
         // have a timezone ID - which is required for this kind of computation.
         $tz = new TimeZone(timezone_name_from_abbr('', $date1->getOffsetInSeconds(), $date1->toString('I')));
         // Now, convert both dates to the same time (actually we only need to convert the
         // second one, as the first will remain in the same timezone)
         $date2 = $tz->translate($date2);
     }
     // Then cut off timezone, by setting both to GMT
     $date1 = DateUtil::setTimeZone($date1, new TimeZone('GMT'));
     $date2 = DateUtil::setTimeZone($date2, new TimeZone('GMT'));
     switch ($interval) {
         case TimeInterval::$YEAR:
             return -($date1->getYear() - $date2->getYear());
         case TimeInterval::$MONTH:
             return -(($date1->getYear() - $date2->getYear()) * 12 + ($date1->getMonth() - $date2->getMonth()));
         case TimeInterval::$DAY:
             return -(intval($date1->getTime() / 86400) - intval($date2->getTime() / 86400));
         case TimeInterval::$HOURS:
             return -(intval($date1->getTime() / 3600) - intval($date2->getTime() / 3600));
         case TimeInterval::$MINUTES:
             return -(intval($date1->getTime() / 60) - intval($date2->getTime() / 60));
         case TimeInterval::$SECONDS:
             return -($date1->getTime() - $date2->getTime());
     }
 }
开发者ID:xp-framework,项目名称:core,代码行数:30,代码来源:DateMath.class.php

示例8: handleForm

 public function handleForm(Context $context, $action)
 {
     if ($action == "createReservation") {
         if (isset($_POST['equip_id']) && $_POST['equip_id'] != "" && (isset($_POST['start_date']) && $_POST['start_date'] != "") && (isset($_POST['length']) && $_POST['length'] != "")) {
             $equipId = $_POST['equip_id'];
             $equip = EquipmentDao::getEquipmentByID($equipId);
             if ($equip != null) {
                 if (SessionUtil::getUserlevel() >= $equip->minUserLevel) {
                     $startDate = $_POST['start_date'];
                     $endDate = DateUtil::incrementDate($startDate, $_POST['length']);
                     $reservations = ReservationDao::getReservationsForEquipmentByDate($equipId, $startDate, $endDate);
                     if (count($reservations) == 0) {
                         $user = UserDao::getUserByUsername(SessionUtil::getUsername());
                         $reservation = ReservationDao::createReservation($user->id, $equipId, $_POST['length'], $startDate, $endDate, $_POST['user_comment']);
                         EmailUtil::sendNewReservationNotices($user, $reservation);
                     } else {
                         $context->addError("Reservations already exist during selected dates ({$startDate} and {$endDate}).");
                     }
                 } else {
                     $context->addError("Cannot reserve equipment (User Level).");
                 }
             } else {
                 $context->addError("No such equipment.");
             }
         } else {
             $context->addError("Required Field Left Blank.");
         }
     } else {
         $context->addError("Incorrect Action.");
     }
 }
开发者ID:ramielrowe,项目名称:Reservation-System-V2,代码行数:31,代码来源:PlaceReservationHandler.php

示例9: payed

 /**
  * 设置订单为已支付
  * @param $orderNo
  * @param $openId
  * @param $wxOrderNo 微信订单号
  */
 public function payed($orderNo, $wxOrderNo)
 {
     $where = array('order_no' => $orderNo);
     $updateData = array('pay_time' => DateUtil::now(), 'order_status' => self::ORDER_PAYED, 'transaction_id' => $wxOrderNo);
     $this->db->where($where);
     $this->db->update($this->table, $updateData);
     return $this->db->affected_rows();
 }
开发者ID:guohao214,项目名称:xinya,代码行数:14,代码来源:OrderModel.php

示例10: insert

 public function insert($timestamp, array &$obj)
 {
     $obj = new TimeIt_Model_EventDate();
     $obj->eid = $obj['id'];
     $obj->date = DateUtil::getDatetime($timestamp, DATEONLYFORMAT_FIXED);
     $obj->cid = $obj['cid'];
     $obj->save();
 }
开发者ID:planetenkiller,项目名称:TimeIt,代码行数:8,代码来源:DB.php

示例11: getPluginData

 function getPluginData($filtAfterDate = null)
 {
     if (!$this->pluginAvailable()) {
         return array();
     }
     if (!SecurityUtil::checkPermission('ZphpBB2::', '::', ACCESS_READ, $this->userNewsletter)) {
         return array();
     }
     //ModUtil::load('ZphpBB2');
     $table_prefix = ModUtil::getVar('ZphpBB2', 'table_prefix', 'phpbb_');
     $TOPICS_TABLE = $table_prefix . "topics";
     $POSTS_TABLE = $table_prefix . "posts";
     $POSTS_TEXT_TABLE = $table_prefix . "posts_text";
     $FORUMS_TABLE = $table_prefix . "forums";
     $connection = Doctrine_Manager::getInstance()->getCurrentConnection();
     $sql = "SELECT forum_id, forum_name FROM {$FORUMS_TABLE} WHERE auth_view <= 0 AND auth_read <= 0";
     $stmt = $connection->prepare($sql);
     try {
         $stmt->execute();
     } catch (Exception $e) {
         return LogUtil::registerError(__('Error in plugin') . ' ZphpBB2: ' . $e->getMessage());
     }
     $userforums = $stmt->fetchAll(Doctrine_Core::FETCH_ASSOC);
     $allowedforums = array();
     foreach (array_keys($userforums) as $k) {
         if (SecurityUtil::checkPermission('ZphpBB2::', ":" . $userforums[$k]['forum_id'] . ":", ACCESS_READ, $this->userNewsletter)) {
             $allowedforums[] = $userforums[$k]['forum_id'];
         }
     }
     if (count($allowedforums) == 0) {
         // user is not allowed to read any forum at all
         return array();
     }
     $sql = "SELECT {$TOPICS_TABLE}.topic_title, {$TOPICS_TABLE}.topic_replies, {$TOPICS_TABLE}.topic_views, {$TOPICS_TABLE}.topic_id, \n                     {$POSTS_TABLE}.post_id, {$POSTS_TABLE}.poster_id, {$POSTS_TABLE}.post_time, \n                     {$POSTS_TEXT_TABLE}.post_subject, {$POSTS_TEXT_TABLE}.post_text, \n                     {$FORUMS_TABLE}.forum_name \n                     FROM {$TOPICS_TABLE} \n                     INNER JOIN {$POSTS_TABLE} ON {$POSTS_TABLE}.topic_id = {$TOPICS_TABLE}.topic_id \n                     INNER JOIN {$POSTS_TEXT_TABLE} ON {$POSTS_TEXT_TABLE}.post_id = {$POSTS_TABLE}.post_id \n                     INNER JOIN {$FORUMS_TABLE} ON {$FORUMS_TABLE}.forum_id = {$TOPICS_TABLE}.forum_id";
     $sql .= " WHERE {$TOPICS_TABLE}.forum_id IN (" . implode(',', $allowedforums) . ")";
     if ($filtAfterDate) {
         $sql .= " AND FROM_UNIXTIME(post_time)>='" . $filtAfterDate . "'";
     }
     $sql .= " ORDER BY post_time DESC LIMIT " . $this->nItems;
     $stmt = $connection->prepare($sql);
     try {
         $stmt->execute();
     } catch (Exception $e) {
         return LogUtil::registerError(__('Error in plugin') . ' ZphpBB2: ' . $e->getMessage());
     }
     $items = $stmt->fetchAll(Doctrine_Core::FETCH_BOTH);
     foreach (array_keys($items) as $k) {
         $items[$k]['topicurl'] = ModUtil::url('ZphpBB2', 'user', 'viewtopic', array('t' => $items[$k]['topic_id']));
         $items[$k]['posturl'] = ModUtil::url('ZphpBB2', 'user', 'viewtopic', array('p' => $items[$k]['post_id'] . '#' . $items[$k]['post_id']));
         $items[$k]['postdate'] = DateUtil::getDatetime($items[$k]['post_time']);
         $items[$k]['username'] = UserUtil::getVar('uname', $items[$k]['poster_id']);
         $items[$k]['nl_title'] = $items[$k]['topic_title'];
         $items[$k]['nl_url_title'] = System::getBaseUrl() . $items[$k]['posturl'];
         $items[$k]['nl_content'] = $items[$k]['forum_name'] . ', ' . $items[$k]['username'] . "<br />\n" . $items[$k]['post_text'];
         $items[$k]['nl_url_readmore'] = $items[$k]['nl_url_title'];
     }
     return $items;
 }
开发者ID:nmpetkov,项目名称:ZphpBB2,代码行数:58,代码来源:ZphpBB2.php

示例12: execute

 /**
  * @see TemplatePluginModifier::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     if (isset($tagArgs[2])) {
         $useStrftime = $tagArgs[2] ? true : false;
     } else {
         $useStrftime = isset($tagArgs[1]) ? true : false;
     }
     return DateUtil::formatDate(isset($tagArgs[1]) ? $tagArgs[1] : null, $tagArgs[0], false, $useStrftime);
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:12,代码来源:TemplatePluginModifierDate.class.php

示例13: smarty_function_timezoneselect

/**
 * Template plugin to display timezone list.
 *
 * Example {timezoneselect selected='Timezone'}.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   The Zikula_View.
 *
 * @see   function.timezoneselect.php::smarty_function_timezoneselect().
 *
 * @return string The results of the module function.
 */
function smarty_function_timezoneselect($params, Zikula_View $view)
{
    require_once $view->_get_plugin_filepath('function', 'html_options');
    $timezones = DateUtil::getTimezones();
    if (!isset($params['selected']) || empty($params['selected']) || !isset($timezones[$params['selected']])) {
        $params['selected'] = System::getVar('timezone_offset');
    }
    return smarty_function_html_options(array('options' => $timezones, 'selected' => $params['selected'], 'print_result' => false), $view);
}
开发者ID:projectesIF,项目名称:Sirius,代码行数:21,代码来源:function.timezoneselect.php

示例14: smarty_modifier_dateformatHuman

/**
 * Smarty modifier to format datetimes in a more Human Readable form 
 * (like tomorow, 4 days from now, 6 hours ago)
 *
 * Example
 * <!--[$futuredate|dateformatHuman:'%x':'2']-->
 *
 * @author   Erik Spaan
 * @since    05/03/09
 * @param    string   $string   input datetime string
 * @param    string   $format   The format of the regular date output (default %x)
 * @param    string   $niceval  [1|2|3|4] Choose the nice value of the output (default 2)
 *                                    1 = full human readable
 *                                    2 = past date > 1 day with dateformat, otherwise human readable
 *                                    3 = within 1 day human readable, otherwise dateformat
 *                                    4 = only use the specified format
 * @return   string   the modified output
 */
function smarty_modifier_dateformatHuman($string, $format = '%x', $niceval = 2)
{
    $dom = ZLanguage::getModuleDomain('News');
    if (empty($format)) {
        $format = '%x';
    }
    // store the current datetime in a variable
    $now = DateUtil::getDatetime();
    if (empty($string)) {
        return DateUtil::formatDatetime($now, $format);
    }
    if (empty($niceval)) {
        $niceval = 2;
    }
    // now format the date with respect to the current datetime
    $res = '';
    $diff = DateUtil::getDatetimeDiff($now, $string);
    if ($diff['d'] < 0) {
        if ($niceval == 1) {
            $res = _fn('%s day ago', '%s days ago', abs($diff['d']), abs($diff['d']), $dom);
        } elseif ($niceval < 4 && $diff['d'] == -1) {
            $res = __('yesterday', $dom);
        } else {
            $res = DateUtil::formatDatetime($string, $format);
        }
    } elseif ($diff['d'] > 0) {
        if ($niceval > 2) {
            $res = DateUtil::formatDatetime($string, $format);
        } elseif ($diff['d'] == 1) {
            $res = __('tomorrow', $dom);
        } else {
            $res = _fn('%s day from now', '%s days from now', $diff['d'], $diff['d'], $dom);
        }
    } else {
        // no day difference
        if ($diff['h'] < 0) {
            $res = _fn('%s hour ago', '%s hours ago', abs($diff['h']), abs($diff['h']), $dom);
        } elseif ($diff['h'] > 0) {
            $res = _fn('%s hour from now', '%s hours from now', $diff['h'], $diff['h'], $dom);
        } else {
            // no hour difference
            if ($diff['m'] < 0) {
                $res = _fn('%s minute ago', '%s minutes ago', abs($diff['m']), abs($diff['m']), $dom);
            } elseif ($diff['m'] > 0) {
                $res = _fn('%s minute from now', '%s minutes from now', $diff['m'], $diff['m'], $dom);
            } else {
                // no min difference
                if ($diff['s'] < 0) {
                    $res = _fn('%s second ago', '%s seconds ago', abs($diff['s']), abs($diff['s']), $dom);
                } else {
                    $res = _fn('%s second from now', '%s seconds from now', $diff['s'], $diff['s'], $dom);
                }
            }
        }
    }
    return $res;
}
开发者ID:aksiide,项目名称:SuperPlugin-generator,代码行数:75,代码来源:modifier.dateformatHuman.php

示例15: getAdsByDay

 public static function getAdsByDay($date)
 {
     $query = "SELECT * FROM " . Database::addPrefix('webads') . " WHERE StartingMonday = '" . DateUtil::findPreviousMonday($date) . "'";
     $result = Database::doQuery($query);
     $webads = array();
     while ($row = mysql_fetch_assoc($result)) {
         $webads[] = WebAdDao::makeAd($row);
     }
     return $webads;
 }
开发者ID:ramielrowe,项目名称:Web-Ads,代码行数:10,代码来源:WebAdDao.php


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