Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the india time in laravel 5.2? [duplicate]

I am using laravel 5.2

I want to save the India time in our created field can anyone help me how to do that. What type of setting I have to do that when user registers? I want the India time to be stored on created_at field. Like in whatsapp chat you saw that when we chat in India it will display the India timings when we chat.

Here is my Code:

$current = Carbon::now();
$current = new Carbon();
$today = Carbon::today();

but it returns me UK time date.

like image 619
kunal Avatar asked Feb 15 '17 08:02

kunal


People also ask

How is India time zone set?

you can set the timezone by date_default_timezone_set('Asia/Kolkata'); check PHP: Asia Manual for other timezones in Asia.


2 Answers

Go to your_project/config/app.php, there is a line:

'timezone' => ''

set it to:

'timezone' => 'Asia/Kolkata'

It will set the default timezone to Asia/Kolkata. After setting this you will get Indian time.

Here is the list of Supported Timezones

like image 196
Mayank Pandeyz Avatar answered Sep 19 '22 04:09

Mayank Pandeyz


$var  = Carbon::now('Asia/Kolkata');
return $time = $var->toTimeString();

I had the same issue. The above code is working fine for me. Hope it helps someone.

like image 24
Abhilash Avatar answered Sep 19 '22 04:09

Abhilash