I am using the following code to get current IST time. But it only gives the system time. I changed my system time due to some reason. So i get only system time instead of current time.
$time_now=mktime(date('h')+5,date('i')+30,date('s'));
$date = date('d-m-Y H:i', $time_now);
echo $date; 8 Answers
Set your system time correctly, so your system knows its correct timezone and the correct time there. In PHP, set your desired timezone, then just print the date:
date_default_timezone_set('Asia/Kolkata');
echo date('d-m-Y H:i');Don't do manual offset calculations unless you know exactly what you're doing, it's way too fickle.
4Get exact Current Indian Time in PHP
$date = date_default_timezone_set('Asia/Kolkata');
//If you want Day,Date with time AM/PM
echo $today = date("F j, Y, g:i a T");
//Get Only Current Time 00:00 AM / PM
echo $today = date("g:i a"); Use now() method it gave current time.
$query = "UPDATE (table name) SET (column) = now() WHERE (condition)";
Note: Make sure that type of the column in the database must be DATETIME type.
1To get the user current time you will need javascript.
if you want to make default timezone on your pages you can use date_default_timezone_set
You can read about this in: HERE
Notice: date_default_timezone_set(): Timezone ID 'Asia/Mumbai' is invalid in D:\Program Files\wamp\www\PHP\...
Only date_default_timezone_set('Asia/Kolkata') is Showing Valid In PHP 5.4.16 Ver :)
:)
Use date_default_timezone_set :
if (function_exists('date_default_timezone_set'))
{ date_default_timezone_set('Asia/Kolkata');
}
echo date('Y-m-d h-i-s'); // set the timezone first
if(function_exists('date_default_timezone_set')) { date_default_timezone_set("Asia/Kolkata");
}
$date = date("m/d/Y");
echo $date;Before adding the date function use the timezone declaration first.
Set your system time correctly, so your system knows its correct timezone and the correct time there. In PHP, set your desired timezone, then just print the date:
date_default_timezone_set('Asia/Kolkata'); echo date('d-m-Y H:i');