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;
Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
PHP time() Function$t=time(); echo($t . "<br>"); echo(date("Y-m-d",$t));
PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With