How to display current Indian time in PHP

How to display current Indian time in PHP

This small snippet explains how to get Indian Time in PHP without changing the server times and timezones. So irrespective of whether your server is in PST or GMT, you can still display IST when displaying this with PHP.

This can be more reliable than simply adding or subtracting the number of seconds in a day or a month to a timestamp because of daylight saving time. PHP’s time() returns a current unix timestamp. With this, you can use the date() function to format it to your needs.

Example using date

This expression will return NOW in format Y-m-d H:i:s.

<?php

$timezone = new DateTimeZone(“Asia/Kolkata” );
$date = new DateTime();
$date->setTimezone($timezone );
echo $date->format(‘Y-m-d H:i:s’);

?>




Categories: Codeigniter,Php

Tags: ,,,

Leave A Reply

Your email address will not be published.

error: Alltutorial.in content is protected !!