YogeshChauhan . com

How to set default timezone using PHP?

in PHP on February 25, 2021

PHP has date_default_timezone_set() function that we can use to set the default timezone.

Here’s how to use this function:


date_default_timezone_set("America/Chicago");

echo date_default_timezone_get();

//America/Chicago

//OR

date_default_timezone_set("UTC");

echo date_default_timezone_get();

//UTC

Be careful, when you set the timezone, it will set in all date functions used inside the page. No matter what country it is, it will be that set timezone in all date functions.

Here is the list of all supported timezones.

It will return FALSE is you don’t pass the valid timezone.

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

Unary Operators in JavaScriptJavaScriptEssential SQL Commands We Need to KnowSQL/MySQLHow to add multiple components in React app?ReactMIN, MAX, COUNT, AVG and SUM in SQLSQL/MySQLHow to add multiple Columns in CSS like Bootstrap?CSSHow to change CSS with jQuery?CSSWhat are CSS Specificity Rules and how does browser apply them?CSSArray.from() Method in JavaScriptJavaScriptThe SQL UNION OperatorSQL/MySQLHow to remove border from :visited image, link or button?CSS4 different Ways to Get JavaScript OutputJavaScript3 Types of Arrays in PHPPHP