Reputation: 5997
I am saving my timestamp in Laravel using the following.
Carbon::now()->timestamp;
How do you convert a timestamp into a specific time format with a specific timezone (using Carbon)?
$unix_time_stamp = "1572095520";
$date = Carbon::createFromTimestamp($unix_time_stamp);
$date->setTimezone('Pacific/Auckland')->format('Y-m-d H:i:s');
I am getting incorrect result on this one, should be Oct 27
Upvotes: 3
Views: 2407
Reputation:
Please try the following.
$unix_time_stamp = '1572095520';
$converted = Carbon::createFromTimestamp($unix_time_stamp,'Pacific/Auckland')
->toDateTimeString();
Upvotes: 3
Reputation: 491
Go to config -> app.php and change 'timezone' => 'Pacific/Auckland',
Upvotes: 1