PHP 5 Date and Time

PHP date function is an in-built function that simplify working with date data types. The PHP date function is used to format a date or time into a human readable format. It can be used to display the date of article was published. record the last updated a data in a database.

PHP Date Syntax

PHP set Timezone Programmatically

The date_default_timezone_set function allows you to set the default time zone from a PHP script.

  • “date_default_timezone_set()” is the function that sets the default time zone
  • “string $timezone_identifier” is the time zone identifier
  • The script below displays the time according to the default time zone set in php.ini.

    It then changes the default time zone to Asia/Calcutta and displays the time again.

    Example -

    Getting a list of available time zone identifiers

    Before we look at how to set the default time zone programmatically, let’s look at how to get a list of supported time zones.

    Example -

    Example -