当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP IntlCalendar getErrorMessage()用法及代码示例


IntlCalendar::getErrorMessage()函数是PHP中的内置函数,用于通过使用IntlCalendar::getErrorCode()或intlcal_get_error_code()函数返回与错误相关的错误消息(如果存在任何错误)。

用法:

  • 面向对象的风格
    string IntlCalendar::getErrorMessage( void )
  • 程序风格
    string intlcal_get_error_message( IntlCalendar $calendar )

参数:该函数使用单个参数$calendar,该参数将日历对象保存在过程样式接口上。

返回值:该函数返回与该对象上的函数调用中发生的上一个错误相关的错误消息,或指示错误不存在的字符串。

以下示例程序旨在说明PHP中的IntlCalendar::getErrorMessage()函数:



程序:

<?php 
  
// Set the DateTime zone 
ini_set('date.timezone', 'Asia/Calcutta'); 
  
// Set the intl error level 
ini_set("intl.error_level", E_WARNING); 
  
// Declare a DateTime object and store it into variable 
$calendar = IntlCalendar::fromDateTime('2019-03-21 09:19:29'); 
  
// Display the error code and message 
var_dump($calendar->getErrorMessage()); 
  
// Declare a DateTime object and store it into variable 
$calendar->fieldDifference(-34E403, IntlCalendar::FIELD_ZONE_OFFSET); 
  
// Display the error code and message 
var_dump($calendar->getErrorMessage()); 
  
?>
输出:
PHP Warning: IntlCalendar::fieldDifference():intlcal_field_difference:Call to ICU method has
failed in /home/22bd84b151f5397224d747dadc65338e.php on line 16
string(12) "U_ZERO_ERROR"
string(81) "intlcal_field_difference:Call to ICU method has failed:U_ILLEGAL_ARGUMENT_ERROR"

参考: https://www.php.net/manual/en/intlcalendar.geterrormessage.php

相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | IntlCalendar getErrorMessage() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。