15

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.

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
kunal
  • 4,122
  • 12
  • 40
  • 75

3 Answers3

46

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

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
  • Its better to set these in `.env` file and use that in `app.php` `date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));` – Ankit Jindal Mar 02 '21 at 03:56
2
$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.

Abhilash
  • 39
  • 1
  • 10
1

you can use this code to set timezone in laravel

config(['app.timezone' => 'Asia/Kolkata']);
Ayman Elshehawy
  • 2,746
  • 23
  • 21