PHP IntlDateFormatter format () Function

PHP

Syntax:
  • Object Oriented Style:
    string IntlDateFormatter::format (mixed  $value)
  • Procedural style:
    string datefmt_format (IntlDateFormatter $fmt, mixed $value)
Parameters:This function uses two parameters as above and described below:
  • fmt:this parameter contains a date object resource.
  • value:this parameter contains a value in the format. It can be a DateTimeInterface object, an IntlCalendar object, or a numeric type representing the number of seconds. If a DateTime or IntlCalendar object is passed, it is not considered.
Return Value:This function returns a formatted string on success, or False on an error. The following program illustrates the IntlDateFormatter::format() function in PHP:Program :  
// Create a date formatter $fmt = datefmt_create ( ' en_US' , IntlDateFormatter::LONG, IntlDateFormatter::LONG, 'Asia / Kolkata' , IntlDateFormatter::GREGORIAN );  
// Display the date in the specified format echo 'Formatted output using object oriented style:' . $fmt -> format (0). "" ; echo ' Formatted output using procedural style: ' . datefmt_format ( $fmt , 0). "" ;  
// Create a date formatter $fmt = datefmt_create ( 'en_US' , IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Asia / Kolkata' , IntlDateFormatter::GREGORIAN );  
// Display the date in the specified format echo 'Formatted output using object oriented style:' . $fmt -> format (0). "" ; echo ' Formatted output using procedural style: ' . datefmt_format ( $fmt , 0);  
?>
Exit:
Formatted output using object oriented style: January 1, 1970 at 5:30:00 AM GMT + 5: 30 Formatted output using procedural style: January 1, 1970 at 5:30:00 AM GMT + 5: 30 Formatted output using object oriented style: 1 / 1/70, 5:30 AM Formatted output using procedural style: 1/1/70, 5:30 AM
Link: https://www.php.net/manual/en/intldateformatter.format.php



Get Solution for free from DataCamp guru