How to change default Timezone in PHP


In PHP, we can set the time zone using the date_default_timezone_set function.

Syntax
date_default_timezone_set(timezone)
Parameter Description
timezone (Required) Specifies the timezone to set as the default. List of Available Timezones in PHP https://www.vrsofttech.com/php-mysql/available-timezones-in-php

Set the default timezone for India

Once we have set the time zone, any date and time functions in PHP script will use the default time zone.The time zone 'Asia/Kolkata' corresponds to the Indian Standard Time (IST).Here's an example of how to use it:

Example
<?php
  //Set time zone for India
  date_default_timezone_set("Asia/Kolkata");

  //Get default Timezone
  echo date_default_timezone_get();

  //Get the current date and time
  $currentDateTime = date("Y-m-d h:i:s a",time());

  echo "<br>".$currentDateTime;
?>