Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Get or Set default Timezone for PHP Script

    How to Get or Set default Timezone for PHP Script

    By RahulFebruary 22, 20151 Min Read

    This article will help you to how to set or get timezone in a php script using date_default_timezone_set() and date_default_timezone_get() inbuilt php functions.

    Advertisement
  • Read: How to Setup Timezone in php.ini or PHP Script
  • How to Set Timezone in PHP Script

    You can set default timezone in a single php script using date_default_timezone_set() function. This timezone is used as default timezone for other functions of php script.

    First choose correct timezone for your php script to use. Use below link to find out list of time zones available in php.

  • http://php.net/manual/en/timezones.php
  • Now edit php script and add below line at top of script with preferred timezone. For example you select “America/New_York” as your default timezone.

    <?php
     date_default_timezone_set("America/New_York");
    
    ?>
    

    How to Get Default Timezone of PHP

    To get current set default timezone in php use date_default_timezone_get() function anywhere inside your php script. for example –

    <?php
     echo date_default_timezone_get();
    
    ?>
    

    date PHP time timezone
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    10 Simple Ways to Speed Up Your WordPress Website

    10 Simple Ways to Speed Up Your WordPress Website

    View 1 Comment

    1 Comment

    1. Php Professional on August 1, 2017 4:59 am

      Great tutorial. This tutorial was really useful to set default timezone in php file.

      Thanks.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.