Change language

PHP IntlDateFormatter formatObject () Function

Syntax:
  • Object Oriented Style:
    string IntlDateFormatter::formatObject (object  $object, mixed $format = NULL, string $locale = NULL)
  • Procedural style:
    string datefmt_format_object (object $object, mixed $format = NULL, string $locale = NULL)
Parameters:This function takes three parameters as above and described below:
  • object:this parameter contains an object of type IntlCalendar or DateTime.
  • format:this parameter contains a date format for setting the date in the specified format. An array with two values ​​can be used (the first sets the date style, and the second sets the time style. The constants are IntlDateFormatter::NONE, IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG, IntlDateFormatter::FULL), integer or string format ... NULL is used for the default style.
  • locale:This parameter contains the locale to use. NULL is used for the default locale.
Return Value:This function returns a string in the specified format on success, or False on error.The program below illustrates the IntlDateFormatter::formatObject() function in PHP:Program :  
// Set time zone and locale ini_set ( ’date.timezone’ , ’Asia / Calcutta’ ); ini_set ( ’intl.default_locale’ , ’en_US’ );  
// Create an IntlCalendar from a DateTime object or string $calander = IntlCalendar::fromDateTime ( ’2019-10 -05 09: 19: 29’ );  
// Display the date in the specified format echo "Default date format = >" . IntlDateFormatter::formatObject ( $calander ). "" ;  
// Display the date in the specified format echo "Date in string format = >" . IntlDateFormatter::formatObject ( $calander , "dd MM yyyy " ). "" ;  
// Display the date in the specified format echo "Date in long format = >" . IntlDateFormatter::formatObject ( $calander , IntlDateFormatter::TRADITIONAL ). "" ;  
// Display the date in the specified format echo "Date in array format = >" , IntlDateFormatter::formatObject ( $calander , array ( IntlDateFormatter::NONE, IntlDateFormatter::FULL) );  
?>
Exit:
Default date format = > Oct 5, 2019, 9:19:29 AM Date in string format = > 05 10 2019 Date in long format = > Saturday, October 5, 2019 at 9:19:29 AM India Standard Time Date in array format = > 9:19:29 AM India Standard Time
Link: https : //www.php.net/manual/en/intldateformatter.formatobject.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method