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


PHP date_parse函数代码示例

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


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

示例1: parse_time

 /**
  * Parse a sentence for time
  *
  * @param string $text
  * @param bool $replace_words
  *
  * @return string|array
  */
 function parse_time($text, $replace_words = false)
 {
     $matches = [];
     if ($replace_words) {
         $text = strtolower($text);
         $phrases = ['0:00' => 'midnight', '12:00' => 'noon', '12:00' => 'midday'];
         foreach ($phrases as $key => $phrase) {
             $text = str_replace($phrase, $key, $text);
         }
     }
     preg_match_all('/(\\d{1,2}[\\:]?(\\d{1,2})?\\s?(am|pm)?)/i', $text, $matches);
     $matches = array_slice($matches[0], 0, 2);
     if (empty($matches[0])) {
         return false;
     }
     $results = array_map(function ($match) {
         if (is_array($match)) {
             return [date_parse(trim($match[0])), date_parse(trim($match[1]))];
         }
         return date_parse(trim($match));
     }, $matches);
     $results = array_map(function ($result) {
         $is_nested = isset($result[1]);
         $items = $is_nested ? $result : [$result];
         for ($i = 0; $i < count($items); $i++) {
             $items[$i]['period'] = $items[$i]['hour'] > 12 ? 'PM' : 'AM';
         }
         return $is_nested ? $items : $items[0];
     }, $results);
     return isset($results[1]) ? $results : $results[0];
 }
开发者ID:invokemedia,项目名称:parsetime,代码行数:39,代码来源:parsetime.php

示例2: call_for_papers

 /**
  * @param $to
  * @param $data
  * @return bool
  */
 public function call_for_papers($to, $data)
 {
     $this->CI->load->library('parser');
     $view_data = array('journal_name' => $data['journal_name'], 'issue' => $data['issue'], 'volume' => $data['volume'], 'paper_open_date' => date_parse($data['open_date'])['day'], 'paper_open_month' => date_parse($data['open_date'])['month'], 'paper_open_year' => date_parse($data['open_date'])['year'], 'deadline_date' => date_parse($data['collection_date'])['day'], 'deadline_month' => date_parse($data['collection_date'])['month'], 'deadline_year' => date_parse($data['collection_date'])['year'], 'publication_date' => date_parse($data['publishing_date'])['day'], 'publication_month' => date_parse($data['publishing_date'])['month'], 'publication_year' => date_parse($data['publishing_date'])['year'], 'link' => $data['registration_link'], 'chief_editor_email' => $data['chief_editor_email']);
     $body_string = $this->CI->parser->parse('email/call_for_papers', $view_data, TRUE);
     return $this->send($to, "Call for Papers", $body_string);
 }
开发者ID:sandeepa91,项目名称:JMS-V1,代码行数:12,代码来源:EmailSender.php

示例3: collectData

 public function collectData(array $param)
 {
     function fetchArticle($link)
     {
         $page = file_get_html($link);
         $contenu = $page->find(".article-text")[0];
         return strip_tags($contenu);
     }
     $html = '';
     $html = file_get_html('http://www.courrierinternational.com/article') or $this->returnError('Error.', 500);
     $element = $html->find(".type-normal");
     $article_count = 1;
     foreach ($element as $article) {
         $item = new \Item();
         $item->uri = "http://www.courrierinternational.com" . $article->find("a")[0]->getAttribute("href");
         $item->content = fetchArticle("http://www.courrierinternational.com" . $article->find("a")[0]->getAttribute("href"));
         $item->title = strip_tags($article->find("h2")[0]);
         $dateTime = date_parse($article->find("time")[0]);
         $item->timestamp = mktime($dateTime['hour'], $dateTime['minute'], $dateTime['second'], $dateTime['month'], $dateTime['day'], $dateTime['year']);
         $this->items[] = $item;
         $article_count++;
         if ($article_count > 5) {
             break;
         }
     }
 }
开发者ID:j0k3r,项目名称:rss-bridge,代码行数:26,代码来源:CourrierInternationalBridge.php

示例4: is_valid_datetime

 /**
  * 
  */
 public function is_valid_datetime($date)
 {
     // is that a date
     $parsed_date = date_parse((string) $date);
     if (!$parsed_date) {
         return false;
     }
     // if this is a date in an expected format
     if (empty($parsed_date['errors'])) {
         $datetime = explode(' ', (string) $date);
         $no = count($datetime);
         if ($no === 1) {
             $format = 'Y-m-d';
         } elseif ($no === 2) {
             $not = count(explode(':', $datetime[1]));
             if ($not === 2) {
                 $format = 'Y-m-d H:i';
             } elseif ($not === 3) {
                 $format = 'Y-m-d H:i:s';
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         // if this is a date but in a different format
         $format = 'Y-m-d H:i:s';
     }
     return $format;
 }
开发者ID:patlegris,项目名称:On-Off,代码行数:34,代码来源:class-helper.php

示例5: parseDateOptions

 private function parseDateOptions($withDates)
 {
     $this->fineDates = "";
     if (empty($_POST['doodle_dates'])) {
         app_controller::$err->add('post_empty_doodleDates');
         return;
     }
     $date_string = app_controller::$strcln->esc($_POST['doodle_dates']);
     //exit($date_string);
     $date_array = explode(",", $date_string);
     //exit(print_r($date_array));
     $this->fineDates = "";
     $date_array_count = count($date_array);
     $date_array_counter = 0;
     foreach ($date_array as $date) {
         $date_array_counter++;
         if (!($parsed_date = date_parse($date))) {
             app_controller::$err->add('date_parser_failed');
             return;
         }
         $this->fineDates .= $parsed_date['day'] . "." . $parsed_date['month'] . "." . $parsed_date['year'];
         if ($date_array_count === $date_array_counter) {
         } else {
             $this->fineDates .= ",";
         }
     }
     $this->makeQuery($withDates);
 }
开发者ID:kmm1k,项目名称:lapdoodle,代码行数:28,代码来源:makenewpoll.php

示例6: inscripciones

 /**
  * http://yourproject/reportes/inscripciones
  */
 public function inscripciones()
 {
     //verificar sesion de usuario
     if (!$this->validUser()) {
         return false;
     }
     // verificar si hay datos POST
     if (isset($_POST["monthdate"]) && $_POST["monthdate"] != null) {
         $partes = explode("/", $_POST["monthdate"]);
         $mes = $partes[0];
         $anho = $partes[1];
     } else {
         //usar la fecha actual
         $today = date("Y-m-d");
         $dateAtributes = date_parse($today);
         $mes = $dateAtributes['month'];
         $anho = $dateAtributes['year'];
         //anteponer un cero a los meses con valor numerico menor que diez
         $mes = $mes < 10 ? "0" . $mes : $mes;
     }
     // cargar modelo, ejecutar la accion, pasar los datos a una variable
     $model = $this->loadModel('PersonasModel');
     try {
         $personaList = $model->listInscritosEnMes($mes, $anho);
     } catch (Exception $e) {
         $this->errorMessageView($e->getMessage());
         return;
     }
     // cargar modelo de pagos para averiguar el nombre del mes
     $pagos_model = $this->loadModel('PagosModel');
     $nombreMes = $pagos_model->nombreMes((int) $mes);
     // mostrar vista del reporte
     require 'application/reports/repinscripcionesdemes.php';
 }
开发者ID:BriptimusPrimus,项目名称:gym-aerys,代码行数:37,代码来源:reportes.php

示例7: generateUniqueName

 public static function generateUniqueName($title, $year)
 {
     $name_base = str_replace(array_keys(self::$TRANSLITERATABLE_CHARACTERS), array_values(self::$TRANSLITERATABLE_CHARACTERS), $title);
     $name_base = strtolower($name_base);
     $name_base = preg_replace("/[']/", '', $name_base);
     $name_base = preg_replace("/[^a-z0-9]/", '_', $name_base);
     $name_base = preg_replace('/_+/', '_', $name_base);
     if (strlen($year) > 4) {
         $year = date_parse($year);
         $year = $year["year"];
     }
     $approved = false;
     $try = 0;
     while (!$approved) {
         $number_length = 0;
         if ($try > 0) {
             $number_length = strlen($try) + 1;
         }
         $name = substr($name_base, 0, 254 - strlen($year) - $number_length);
         $name .= '_' . $year;
         if ($try > 0) {
             $name .= '_' . $try;
         }
         $result = null;
         $query = new GameQuery();
         $result = $query->findOneByName($name);
         if ($result != null) {
             $try++;
         } else {
             return $name;
         }
     }
 }
开发者ID:pcmasteratings,项目名称:site,代码行数:33,代码来源:Game.php

示例8: parse

 /**
  * Parses given date/time of given timezone and converts to UTC.
  * If no timezone is given, a UTC date is expected.
  *
  * @param string $date_
  * @param \Components\Timezone $timezone_
  *
  * @return \Components\Date
  */
 public static function parse($date_, Timezone $timezone_ = null, $pattern_ = null)
 {
     $parsed = @date_parse($date_);
     if (null === $timezone_) {
         if (isset($parsed['zone'])) {
             $timezone_ = Timezone::forOffset($parsed['zone'] / 60);
         }
     }
     if (null === $timezone_) {
         $timezone_ = Timezone::utc();
     }
     if (null === $pattern_) {
         $pattern_ = I18n::translate('common/datetime/pattern/parse');
     }
     if (isset($parsed['errors_count']) && 0 < (int) $parsed['errors_count']) {
         $date = \DateTime::createFromFormat($pattern_, $date_, $timezone_->internal());
     } else {
         extract($parsed);
         $date = new \DateTime(sprintf('%1$d-%2$d-%3$d %4$d:%5$d:%6$d', $year, $month, $day, $hour, $minute, $second), $timezone_->internal());
     }
     if (!$date) {
         throw new Exception_IllegalArgument('type/date', 'Unable to parse given date. Try specifying a matching pattern.');
     }
     $date->setTimezone(Timezone::utc()->internal());
     return new static($date);
 }
开发者ID:evalcodenet,项目名称:net.evalcode.components.type,代码行数:35,代码来源:date.php

示例9: local_time

 function local_time()
 {
     $traveller_info = $this->traveller_info();
     $city_info = $this->city_info($traveller_info->traveller->current_city->geoname_id);
     $date = date_parse($city_info->city->localtime);
     return date('g:i A', strtotime($date['hour'] . ":" . $date['minute']));
 }
开发者ID:johndbritton,项目名称:DopplrVBX,代码行数:7,代码来源:dopplr.php

示例10: document_pdf_metadata

 /**
  * @param string $filename
  * @return array
  */
 public static function document_pdf_metadata($filename)
 {
     $result = [];
     exec(PATH_PDFINFO . " '" . addslashes($filename) . "'", $result);
     $seiten = 0;
     $datum = "";
     if (preg_match("/Pages:\\s*([0-9]+)/siu", implode("\n", $result), $matches_page)) {
         $seiten = IntVal($matches_page[1]);
     }
     if (preg_match("/CreationDate:\\s*([a-z0-9 :]+)\n/siu", implode("\n", $result), $matches_date)) {
         $datum = date_parse($matches_date[1]);
         if ($datum && isset($datum["year"]) && $datum["year"] > 1990) {
             $datum = $datum["year"] . "-" . $datum["month"] . "-" . $datum["day"] . " " . $datum["hour"] . ":" . $datum["minute"] . ":" . $datum["second"];
         } else {
             $datum = "0000-00-00 00:00:00";
         }
     }
     if ($seiten > 0) {
         return ["seiten" => $seiten, "datum" => $datum];
     }
     $result = [];
     exec(PATH_IDENTIFY . " {$filename}", $result);
     $anzahl = 0;
     foreach ($result as $res) {
         if (strpos($res, "DirectClass")) {
             $anzahl++;
         }
     }
     return ["seiten" => $anzahl, "datum" => $datum];
 }
开发者ID:CatoTH,项目名称:Muenchen-Transparent,代码行数:34,代码来源:RISPDF2Text.php

示例11: findWeekday

 function findWeekday($date)
 {
     date_default_timezone_set("UTC");
     $f_date = date_create($date);
     $base_date = date_create("2015-08-13");
     $output = "Thursday";
     $list_of_days = array("Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday");
     $p_date = date_parse($date);
     if ($p_date["error_count"] == 0 && checkdate($p_date["month"], $p_date["day"], $p_date["year"])) {
         $days = $base_date->diff($f_date);
         $pos_or_neg = $days->format('%R');
         $days = $days->format('%a');
         $days = $days % 7;
         if ($pos_or_neg == "-") {
             if ($days == 1) {
                 $days = 6;
             } elseif ($days == 2) {
                 $days = 5;
             } elseif ($days == 3) {
                 $days = 4;
             } elseif ($days == 4) {
                 $days = 3;
             } elseif ($days == 5) {
                 $days = 2;
             } elseif ($days == 6) {
                 $days = 1;
             }
         }
         $output = $list_of_days[$days];
     } else {
         $output = "ERROR";
     }
     $output = array($output, $date);
     return $output;
 }
开发者ID:boloround,项目名称:Weekday_Finder,代码行数:35,代码来源:WeekdayFinder.php

示例12: get_xsddatetime

function get_xsddatetime($date = '', $bkeep = false)
{
    if (empty($date)) {
        //$datetime_lastmodified = date_create();
        //$datetime_lastmodified = date_format($datetime_lastmodified, "Y-m-d\TH:i:s\Z");
        return false;
        //date("Y-m-d\TH:i:s\Z");
    } else {
        //		date_default_timezone_set("GMT");
        $temp = date_parse($date);
        if (!empty($temp) && $temp['year'] !== false && $temp['month'] !== false && $temp['day'] !== false) {
            $ret = sprintf("%04d-%02d-%02d", $temp['year'], $temp['month'], $temp['day']);
            if ($temp['hour'] !== false && $temp['minute'] !== false && $temp['second'] !== false) {
                return $ret . sprintf("T%02d:%02d:%02dZ", $temp['hour'], $temp['minute'], $temp['second']);
            } else {
                return $ret;
            }
        } else {
            if ($bkeep) {
                return $date;
            } else {
                return false;
            }
        }
    }
}
开发者ID:DevFactory,项目名称:twitlogic,代码行数:26,代码来源:api-web.php

示例13: getStats

 function getStats()
 {
     $output = '';
     $q_status = $this->modx->newQuery('msOrderStatus', array('active' => 1));
     $q_status->select('id,name,color');
     if ($q_status->prepare() && $q_status->stmt->execute()) {
         while ($row = $q_status->stmt->fetch(PDO::FETCH_ASSOC)) {
             //$output[$row['id']] = $row;
             $output['total_counts'][$row['id']] = array('name' => $row['name'], 'color' => $row['color'], 'count_orders' => $this->modx->getCount('msOrder', array('status' => $row['id'])));
         }
     }
     $q_stats_month = $this->modx->newQuery('msOrder');
     $q_stats_month->select('status,`createdon`, month(`createdon`) AS `order_month`, count(*) AS `order_count`, SUM(cart_cost) AS order_cost');
     $q_stats_month->groupby('month(`createdon`), status');
     $q_stats_month->sortby('createdon', ASC);
     if ($q_stats_month->prepare() && $q_stats_month->stmt->execute()) {
         $output['cart_cost'] = 0;
         $output['cart_count'] = 0;
         while ($row = $q_stats_month->stmt->fetch(PDO::FETCH_ASSOC)) {
             $date = date_parse($row['createdon']);
             $output['stats_month'][$date['year'] . '-' . $date['month']][$row['status']] = array('total_cost' => $row['order_cost'], 'count_orders' => $row['order_count'], 'status' => $row['status']);
             $output['cart_cost'] += $row['order_cost'];
             $output['cart_count'] += $row['order_count'];
         }
         $output['cart_cost'] = number_format($output['cart_cost'], 2, ',', ' ');
         $output['users_count'] = $this->modx->getCount('modUser', array('active' => 1, 'primary_group' => 0));
     }
     return $output;
 }
开发者ID:bendasvadim,项目名称:shopStats,代码行数:29,代码来源:minishop2.class.php

示例14: formatDateRange

 public function formatDateRange()
 {
     $startDateArray = date_parse($this->EventStartDate);
     $endDateArray = date_parse($this->EventEndDate);
     if ($startDateArray["year"] == $endDateArray["year"] && $startDateArray["month"] == $endDateArray["month"] && $startDateArray["day"] == $endDateArray["day"]) {
         // single day range
         return date('M d, Y', strtotime($this->EventStartDate));
     } else {
         if ($startDateArray["year"] == $endDateArray["year"] && $startDateArray["month"] == $endDateArray["month"]) {
             // multi-day, single month range
             $value = date('M d - ', strtotime($this->EventStartDate));
             $value .= date('d, Y', strtotime($this->EventEndDate));
             return $value;
         } else {
             if ($startDateArray["year"] == $endDateArray["year"]) {
                 // same year, spanning months (there days as well)
                 $value = date('M d - ', strtotime($this->EventStartDate));
                 $value .= date('M d, Y', strtotime($this->EventEndDate));
                 return $value;
             } else {
                 // must be different years (therefore months and days as well)
                 $value = date('M d, Y - ', strtotime($this->EventStartDate));
                 $value .= date('M d, Y', strtotime($this->EventEndDate));
                 return $value;
             }
         }
     }
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:28,代码来源:EventPage.php

示例15: reportsAction

 public function reportsAction(Request $request)
 {
     $users = DB::select('select id, first_name, last_name, email from users');
     if ($request->isMethod('post')) {
         $id = substr($request->input('email'), strpos($request->input('email'), ":") + 2);
         $year = $request->input('year');
         $month = $request->input('month');
         $events = DB::select('select users.first_name, events.*, transport.name as t_name, transport.load_consumption,
               transport.moving_consumption, transport.stat_consumption
               from users inner join events on users.id = events.user_id
               left join transport on events.vehicle_id = transport.id
               where year(events.date) = ? and month(events.date) = ?
               AND users.id = ?', [$year, $month, $id]);
         $calc = [];
         foreach ($events as $event) {
             $parsed_arrive = date_parse($event->client_arrive);
             $parsed_leave = date_parse($event->client_leave);
             $hours['arrive'] = $parsed_arrive['hour'] + $parsed_arrive['minute'] / 60;
             $hours['leave'] = $parsed_leave['hour'] + $parsed_leave['minute'] / 60;
             $hours['actual'] = $hours['leave'] - $hours['arrive'] - $event->min_spent / 60;
             $calc[$event->id]['distance'] = (int) $event->spidometer_finish - (int) $event->spidometer_start;
             $calc[$event->id]['fuel'] = $calc[$event->id]['distance'] / 100 * $event->moving_consumption + $event->min_spent / 60 * $event->load_consumption + $hours['actual'] * $event->stat_consumption;
         }
         //        die(var_dump($calc));
         return view('admin/reports', ['events' => $events, 'calc' => $calc, 'users' => $users]);
     }
     return view('admin/reports', ['users' => $users]);
 }
开发者ID:einorler,项目名称:laravel-test,代码行数:28,代码来源:AdminController.php


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