Recently I was stuck with one of the assignments which required Local Indian Timestamp to be inserted into database and was not able to find anything better than this even after much googling.
I hope you find this useful and if there is a better way, Please let me know and I will update this post. I know there is a better way with PHP 5.3+ but this had to work on a lower version.
<?php
/*
* Function to turn a mysql datetime (YYYY-MM-DD HH:MM:SS) into a unix timestamp
* @param str
* The string to be formatted
*/
function convert_datetime($str) {
list($date, $time) = explode(‘ ‘, $str);
list($year, $month, $day) = explode(‘-’, $date);
list($hour, $minute, $second) = explode(‘:’, $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
$time = time();
echo($time . “<hr/>”);
$timezone = new DateTimeZone(“Asia/Kolkata” );
$date = new DateTime();
$date->setTimezone($timezone );
echo convert_datetime($date->format(( ‘Y-m-j H:i:s’ )));
?>
Related Searches on Google which landed visitors on our page recently are
indian time in php
get india time in php
get indian time in php
how to get the indian time php
get the time of india by php
indian current time in php
indian time php
php datetime ist india
php source code date time in india
print current indian time in php
$todayis = date php code in indian time
current indian date and time in php
current time in india in php
date function in php to find india time
display current time for indian timzone php
display india date and time in php code
display india time in php
display indian current time in php
display indian date in php
display indian time + php code
display indian time in php
display time for india
display time india
displaying indian date in php
displaying time in india tutorial in php
get india time php
get india timezone in php
get indian timestamp
get time in india php
getting indian time in ph
gmt time for indian server php
how to display current indian time in php
how to display current time in php of india
how to find currenct time of india in php
how to get current indian time in php
how to get india time using php
how to get indian date in server in php
how to get indian server time
how to get indian time in php
how to get indian time?
india time in php
india time zone in php
india timezone in php
indian timezone in php
php code for indian time
php code to get indian time
php current year date time with timezone india
php get indian time
php india timestamp
php indian time
php source code date for india
php time of india
php time zone india
php to display time in indian time
set indian time in php
show india timing in php
time zne india in php
timestamp php india
timezone in php for india
current indian time get in php
php code for indian date time stamp
Tags: Code Snippets, PHP Programming