{"id":128,"date":"2010-08-29T23:00:53","date_gmt":"2010-08-29T17:30:53","guid":{"rendered":"http:\/\/jesin.tk\/?p=128"},"modified":"2010-09-20T23:03:22","modified_gmt":"2010-09-20T17:33:22","slug":"setting-a-timezone-in-php","status":"publish","type":"post","link":"https:\/\/websistent.com\/setting-a-timezone-in-php\/","title":{"rendered":"Setting a Timezone in PHP"},"content":{"rendered":"<p>Using the javascript date\/time function is easy because its a client-side language so it displays your system time. But its not the same case with PHP. Since its a server-side language it displays the server&#8217;s time which can be irritating because you might have your server located in another country and you might live somewhere else. But changing the timezone is just a few clicks away and whats more, you can even set different timezones for different pages\/directories.<!--more--><\/p>\n<h1><span style=\"text-decoration: underline;\">Method 1:-<\/span> Edit the php.ini file<\/h1>\n<p>Before editing the php.ini file please take a backup of it. Open the php.ini file using a text editor and navigate to the following line.<\/p>\n<p><code class=\"source-code\">date.timezone =<\/code><\/p>\n<p>After the equal to (=) symbol enter the desired timezone. See <a href=\"http:\/\/php.net\/manual\/en\/timezones.php\">list of PHP timezones<\/a> for a complete list of supported timezones. For example<\/p>\n<p><code class=\"source-code\">date.timezone = America\/Mexico_City<\/code><\/p>\n<p>save the php.ini file and restart your web server. Create a PHP file and enter the following code<\/p>\n<p><code class=\"source-code\">&lt;?php print date(\"d\/m\/yy\").\"&lt;br&gt;\".date(\"H:i:s\"); ?&gt;<\/code><\/p>\n<p>save the file and access it via your web browser you should see the date and time of the timezone you entered. This change is done system wide so all web pages will reflect this change.<\/p>\n<h1><span style=\"text-decoration: underline;\">Method 2:-<\/span> Create\/Edit the .htaccess file<\/h1>\n<p>This method is for people using shared web hosting services. Others can also use this method for setting different timezones for different directories. Example, for the main directory you may have the Mexico timezone and for the directory \/images you can have the Australian timezone. Edit the .htaccess file, if its not there create a file named .htaccess inside the www or htdocs or public_html folder. Add the following line to it<\/p>\n<p><code class=\"source-code\">php_value date.timezone [timezone name]<\/code><\/p>\n<p>example,<\/p>\n<p><code class=\"source-code\">php_value date.timezone America\/Mexico_City<\/code><\/p>\n<p>save the .htaccess file and do as mentioned in method 1 to test the configuration.<\/p>\n<h1><span style=\"text-decoration: underline;\">Method 3:-<\/span> Use the ini_set() function<\/h1>\n<p>The ini_set() is a very useful function which allows an user to set specific options for a single page\/file. This method can be used be anyone who want to apply different timezone settings to each of the PHP script.<\/p>\n<p><code class=\"source-code\"><span style=\"text-decoration: underline;\"><strong>Syntax:-<\/strong><\/span> ini_set(\"date.timezone\",\"[timezone name]\");<\/code><\/p>\n<p><code class=\"source-code\"><span style=\"text-decoration: underline;\"><strong>Example:-<\/strong><\/span> ini_set(\"date.timezone\",\"America\/Mexico_City\");<\/code><\/p>\n<p>Add this function to the beginning of every PHP script and you&#8217;re done. So you can have each script show a different time\/date associated with a different timezone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using the javascript date\/time function is easy because its a client-side language so it displays your system time. But its not the same case with PHP. Since its a server-side language it displays the server&#8217;s time which can be irritating because you might have your server located in another country and you might live somewhere [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[8],"tags":[10,24,27],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Setting a Timezone in PHP - Jesin&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/websistent.com\/setting-a-timezone-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting a Timezone in PHP - Jesin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Using the javascript date\/time function is easy because its a client-side language so it displays your system time. But its not the same case with PHP. Since its a server-side language it displays the server&#8217;s time which can be irritating because you might have your server located in another country and you might live somewhere [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/websistent.com\/setting-a-timezone-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Jesin&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/JesinsBlog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/a.jesin\" \/>\n<meta property=\"article:published_time\" content=\"2010-08-29T17:30:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2010-09-20T17:33:22+00:00\" \/>\n<meta name=\"author\" content=\"Jesin A\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:site\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jesin A\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/websistent.com\/setting-a-timezone-in-php\/\",\"url\":\"https:\/\/websistent.com\/setting-a-timezone-in-php\/\",\"name\":\"Setting a Timezone in PHP - Jesin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/websistent.com\/#website\"},\"datePublished\":\"2010-08-29T17:30:53+00:00\",\"dateModified\":\"2010-09-20T17:33:22+00:00\",\"author\":{\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/websistent.com\/setting-a-timezone-in-php\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/websistent.com\/#website\",\"url\":\"https:\/\/websistent.com\/\",\"name\":\"Jesin&#039;s Blog\",\"description\":\"Welcome to the Portal of Technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/websistent.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\",\"name\":\"Jesin A\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"caption\":\"Jesin A\"},\"sameAs\":[\"https:\/\/websistent.com\/\",\"https:\/\/www.facebook.com\/a.jesin\",\"https:\/\/twitter.com\/jesin_a\"],\"url\":\"https:\/\/websistent.com\/author\/a-jesin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting a Timezone in PHP - Jesin&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/websistent.com\/setting-a-timezone-in-php\/","og_locale":"en_US","og_type":"article","og_title":"Setting a Timezone in PHP - Jesin&#039;s Blog","og_description":"Using the javascript date\/time function is easy because its a client-side language so it displays your system time. But its not the same case with PHP. Since its a server-side language it displays the server&#8217;s time which can be irritating because you might have your server located in another country and you might live somewhere [&hellip;]","og_url":"https:\/\/websistent.com\/setting-a-timezone-in-php\/","og_site_name":"Jesin&#039;s Blog","article_publisher":"https:\/\/www.facebook.com\/JesinsBlog","article_author":"https:\/\/www.facebook.com\/a.jesin","article_published_time":"2010-08-29T17:30:53+00:00","article_modified_time":"2010-09-20T17:33:22+00:00","author":"Jesin A","twitter_card":"summary_large_image","twitter_creator":"@jesin_a","twitter_site":"@jesin_a","twitter_misc":{"Written by":"Jesin A","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/websistent.com\/setting-a-timezone-in-php\/","url":"https:\/\/websistent.com\/setting-a-timezone-in-php\/","name":"Setting a Timezone in PHP - Jesin&#039;s Blog","isPartOf":{"@id":"https:\/\/websistent.com\/#website"},"datePublished":"2010-08-29T17:30:53+00:00","dateModified":"2010-09-20T17:33:22+00:00","author":{"@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/websistent.com\/setting-a-timezone-in-php\/"]}]},{"@type":"WebSite","@id":"https:\/\/websistent.com\/#website","url":"https:\/\/websistent.com\/","name":"Jesin&#039;s Blog","description":"Welcome to the Portal of Technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/websistent.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0","name":"Jesin A","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/websistent.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","caption":"Jesin A"},"sameAs":["https:\/\/websistent.com\/","https:\/\/www.facebook.com\/a.jesin","https:\/\/twitter.com\/jesin_a"],"url":"https:\/\/websistent.com\/author\/a-jesin\/"}]}},"_links":{"self":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/128"}],"collection":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":0,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/128\/revisions"}],"wp:attachment":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/categories?post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/tags?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}