Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current IST time in php

Tags:

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; 
like image 378
user1490612 Avatar asked Nov 12 '12 08:11

user1490612


People also ask

How can I get current date and time in PHP?

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.

How get fetch time from database in PHP?

PHP time() Function$t=time(); echo($t . "<br>"); echo(date("Y-m-d",$t));

What is PHP time function?

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()


1 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.

like image 57
deceze Avatar answered Oct 11 '22 23:10

deceze