
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to Detect User Timezone in PHP?
To detect timezone, we can either set a timezone and display or we can directly display. Here, we will see two examples −
- Get and Display the default timezone.
- Set a Timezone and Display it.
Get the Default TimeZone
To get the default timezone in PHP, we will use the following method −
date_default_timezone_get();
Example
Let us see the example −
<?php echo "Default TimeZone: "; echo date_default_timezone_get(); ?>
Output
Default TimeZone:UTC
Set a TimeZone and Display
In this example, we will first set a timezone using the following method −
date_default_timezone_set
To get the timezone we have set above, use the following method −
date_default_timezone_get();
Example
Let us now see the complete example −
<?php echo "Set Default TimeZone"; date_default_timezone_set("Asia/Kolkata"); echo "
Updated TimeZone: "; echo date_default_timezone_get(); ?>
Output
Set Default TimeZone: Updated TimeZone: Asia/Kolkata
- Related Articles
- How to Detect User Timezone in JavaScript?
- How to detect user pressing HOME key in iOS?
- How to detect user inactivity for 5 seconds in iOS?
- How to detect user inactivity for 5 seconds in Android?
- How to detect Android user agent type in general using kotlin?
- How do detect Android user agent type in general?
- How to detect user pressing Home Key in an Activity on Android?
- How to detect user inactivity for 5 seconds in Android using Kotlin?
- How to detect search engine bots with PHP?
- PHP – How to detect character encoding using mb_detect_encoding()
- Detect base64 encoding in PHP?
- Simplest way to detect client locale in PHP
- Detect language from string in PHP
- How to change MySQL timezone?
- Get unix timestamp from string without setting default timezone in PHP

Advertisements