There istimestamp
field (not null) in UTC in database with value: 2019-08-09 20:06:08
.
I tried to convert this time to local time using function:
private function toLocalTime($dateInUTC) {
$time = strtotime($dateInUTC.' UTC');
return date("d/m/Y H:i", $time);
}
Converting is:
$response = []; // Data is present here
foreach($response as $v) {
$v->created_at = $this->toLocalTime($v->created_at);
}
On line where I call $this->toLocalTime()
I get exception:
I have tried this code:
$timestamp = '2019-08-09 10:41:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'UTC');
$date->setTimezone('your/timezone'); //
$new_date = $date->format('your new format'); // Y-m-d H:i:s
Maybe my $timestamp
is empty somewhere?