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


PHP Lang::standardizeDate方法代码示例

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


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

示例1: parse

 /**
  * Parses the given string and returns a DateTime object.
  *
  * @since Symphony 2.3
  * @param string $string (optional)
  *  A string containing date and time, defaults to the current date and time
  * @return DateTime|boolean
  *  The DateTime object, or if the date could not be parsed, false.
  */
 public static function parse($string)
 {
     // Current date and time
     if ($string == 'now' || empty($string)) {
         $date = new DateTime();
         // Timestamp
     } elseif (is_numeric($string)) {
         $date = new DateTime('@' . $string);
         // Attempt to parse the date provided against the Symphony configuration setting
         // in an effort to better support multilingual date formats. Should this fail
         // this block will fallback to just passing the date to DateTime constructor,
         // which will parse the date assuming it's in an American format.
     } else {
         // Standardize date
         // Convert date string to English
         $string = Lang::standardizeDate($string);
         // PHP 5.3: Apply Symphony date format using `createFromFormat`
         $date = DateTime::createFromFormat(self::$settings['datetime_format'], $string);
         if ($date === false) {
             $date = DateTime::createFromFormat(self::$settings['date_format'], $string);
         }
         // Handle dates that are in a different format to Symphony's config
         // DateTime is much the same as `strtotime` and will handle relative
         // dates.
         if ($date === false) {
             try {
                 $date = new DateTime($string);
             } catch (Exception $ex) {
                 // Invalid date, it can't be parsed
                 return false;
             }
         }
         // If the date is still invalid, just return false.
         if ($date === false || $date->format('Y') < 0) {
             return false;
         }
     }
     // Return custom formatted date, use ISO 8601 date by default
     return $date;
 }
开发者ID:hotdoy,项目名称:EDclock,代码行数:49,代码来源:class.datetimeobj.php

示例2: processRawFieldData

 public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
 {
     $status = self::__OK__;
     $timestamp = null;
     if (is_null($data) || $data == '') {
         $timestamp = strtotime(Lang::standardizeDate(DateTimeObj::get(__SYM_DATETIME_FORMAT__, null)));
     } else {
         $timestamp = strtotime(Lang::standardizeDate($data));
     }
     if (!is_null($timestamp)) {
         return array('value' => DateTimeObj::get('c', $timestamp), 'date' => DateTimeObj::getGMT('Y-m-d H:i:s', $timestamp));
     }
     return array('value' => null, 'date' => null);
 }
开发者ID:symphonists,项目名称:datemodified,代码行数:14,代码来源:field.datemodified.php

示例3: format

 /**
  * Formats the given date and time `$string` based on the given `$format`.
  * Optionally the result will be localized and respect a timezone differing
  * from the system default. The default output is ISO 8601.
  * Please note that for best compatibility with European dates it is recommended
  * that your site be in a PHP5.3 environment.
  *
  * @since Symphony 2.2.1
  * @param string $string (optional)
  *  A string containing date and time, defaults to the current date and time
  * @param string $format (optional)
  *  A valid PHP date format, defaults to ISO 8601
  * @param boolean $localize (optional)
  *  Localizes the output, if true, defaults to true
  * @param string $timezone (optional)
  *  The timezone associated with the timestamp
  * @return string|boolean
  *  The formatted date, of if the date could not be parsed, false.
  */
 public static function format($string = 'now', $format = DateTime::ISO8601, $localize = true, $timezone = null)
 {
     // Current date and time
     if ($string == 'now' || empty($string)) {
         $date = new DateTime();
     } elseif (is_numeric($string)) {
         $date = new DateTime('@' . $string);
     } else {
         // Standardize date
         // Convert date string to English
         $string = Lang::standardizeDate($string);
         // PHP 5.3: Apply Symphony date format using `createFromFormat`
         if (method_exists('DateTime', 'createFromFormat')) {
             $date = DateTime::createFromFormat(self::$settings['datetime_format'], $string);
             if ($date === false) {
                 $date = DateTime::createFromFormat(self::$settings['date_format'], $string);
             }
             // Handle dates that are in a different format to Symphony's config
             // DateTime is much the same as `strtotime` and will handle relative
             // dates.
             if ($date === false) {
                 try {
                     $date = new DateTime($string);
                 } catch (Exception $ex) {
                     // Invalid date, it can't be parsed
                     return false;
                 }
             }
         } else {
             try {
                 $date = new DateTime($string);
             } catch (Exception $ex) {
                 // Invalid date, it can't be parsed
                 return false;
             }
         }
         // If the date is still invalid, just return false.
         if ($date === false) {
             return false;
         }
     }
     // Timezone
     // If a timezone was given, apply it
     if ($timezone !== null) {
         $date->setTimezone(new DateTimeZone($timezone));
     } else {
         if (isset(self::$settings['timezone'])) {
             $date->setTimezone(new DateTimeZone(self::$settings['timezone']));
         }
     }
     // Format date
     $date = $date->format($format);
     // Localize date
     // Convert date string from English back to the activated Language
     if ($localize === true) {
         $date = Lang::localizeDate($date);
     }
     // Return custom formatted date, use ISO 8601 date by default
     return $date;
 }
开发者ID:benesch,项目名称:hilton-unar,代码行数:79,代码来源:class.datetimeobj.php

示例4: parse

 /**
  * Parses the given string and returns a DateTime object.
  * Please note that for best compatibility with European dates it is recommended
  * that your site be in a PHP5.3 environment.
  *
  * @since Symphony 2.3
  * @param string $string (optional)
  *  A string containing date and time, defaults to the current date and time
  * @return DateTime|boolean
  *  The DateTime object, or if the date could not be parsed, false.
  */
 public static function parse($string)
 {
     // Current date and time
     if ($string == 'now' || empty($string)) {
         $date = new DateTime();
     } elseif (is_numeric($string)) {
         $date = new DateTime('@' . $string);
     } else {
         // Standardize date
         // Convert date string to English
         $string = Lang::standardizeDate($string);
         // PHP 5.3: Apply Symphony date format using `createFromFormat`
         if (method_exists('DateTime', 'createFromFormat')) {
             $date = DateTime::createFromFormat(self::$settings['datetime_format'], $string);
             if ($date === false) {
                 $date = DateTime::createFromFormat(self::$settings['date_format'], $string);
             }
             // Handle dates that are in a different format to Symphony's config
             // DateTime is much the same as `strtotime` and will handle relative
             // dates.
             if ($date === false) {
                 try {
                     $date = new DateTime($string);
                 } catch (Exception $ex) {
                     // Invalid date, it can't be parsed
                     return false;
                 }
             }
         } else {
             try {
                 $date = new DateTime($string);
             } catch (Exception $ex) {
                 // Invalid date, it can't be parsed
                 return false;
             }
         }
         // If the date is still invalid, just return false.
         if ($date === false) {
             return false;
         }
     }
     // Return custom formatted date, use ISO 8601 date by default
     return $date;
 }
开发者ID:bauhouse,项目名称:Piano-Sonata,代码行数:55,代码来源:class.datetimeobj.php

示例5: format

 /**
  * Formats the given date and time `$string` based on the given `$format`.
  * Optionally the result will be localized and respect a timezone differing
  * from the system default. The default output is ISO 8601.
  *
  * @since Symphony 2.2.1
  * @param string $string (optional)
  *  A string containing date and time, defaults to the current date and time
  * @param string $format (optional)
  *  A valid PHP date format, defaults to ISO 8601
  * @param boolean $localize (optional)
  *  Localizes the output, if true, defaults to true
  * @param string $timezone (optional)
  *  The timezone associated with the timestamp
  * @return string
  *  The formatted date
  */
 public static function format($string = 'now', $format = DateTime::ISO8601, $localize = true, $timezone = null)
 {
     // Current date and time
     if ($string == 'now' || empty($string)) {
         $date = new DateTime();
     } elseif (is_numeric($string)) {
         $date = new Datetime(date(DateTime::ISO8601, $string));
     } else {
         // Standardize date
         // Convert date string to English
         $string = Lang::standardizeDate($string);
         // PHP 5.3: Apply Symphony date format using `createFromFormat`
         if (method_exists('DateTime', 'createFromFormat')) {
             $date = DateTime::createFromFormat(__SYM_DATETIME_FORMAT__, $string);
             if ($date === false) {
                 $date = DateTime::createFromFormat(__SYM_DATE_FORMAT__, $string);
             }
         } else {
             $date = strptime($string, DateTimeObj::dateFormatToStrftime(__SYM_DATETIME_FORMAT__));
             if ($date === false) {
                 $date = DateTimeObj::dateFormatToStrftime(__SYM_DATE_FORMAT__, $string);
             }
             if (is_array($date)) {
                 $date = date(DateTime::ISO8601, mktime($date['tm_hour'], $date['tm_min'], $date['tm_sec'], $date['tm_mon'] + 1, $date['tm_mday'], 1900 + $date['tm_year']));
                 $date = new DateTime($date);
             }
         }
         // Handle non-standard dates (ie. relative dates, tomorrow etc.)
         if ($date === false) {
             $date = new DateTime($string);
         }
     }
     // Timezone
     if ($timezone !== null) {
         $date->setTimezone(new DateTimeZone($timezone));
     }
     // Format date
     $date = $date->format($format);
     // Localize date
     // Convert date string from English back to the activated Language
     if ($localize === true) {
         $date = Lang::localizeDate($date);
     }
     // Return custom formatted date, use ISO 8601 date by default
     return $date;
 }
开发者ID:rainerborene,项目名称:symphony-2,代码行数:63,代码来源:class.datetimeobj.php

示例6: __getDate

 /**
  * Convert string to Datetime object. Log error, if given date is invalid.
  *
  * @param string $string
  *  String to be converted to Datetime object
  * @return Datetime
  *	Returns a Datetime object on success or `NULL` on failure
  */
 private function __getDate($string)
 {
     // Get date and time object
     try {
         $date = new DateTime(fieldDate::cleanFilterString(Lang::standardizeDate($string)));
     } catch (Exception $e) {
         Symphony::$Log->pushToLog('Date and Time could not parse the following date: ' . trim($string) . '. It will be ignored for data source filtering.', E_ERROR, true);
         $date = NULL;
     }
     return $date;
 }
开发者ID:brendo,项目名称:datetime,代码行数:19,代码来源:field.datetime.php


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