I have a code that fetches the date and time an order is made. I am doing this in Laravel PHP. I know how to echo the date in PHP using date().
The challenge here is however converting the timezone. The code below works and outputs the date correctly but it's instead adding a prefix 1
so that my date now looks something similar to
1
February 19, 2022 05:14 am
The code is:
{date_default_timezone_set('Africa/Nairobi')} {$order_order_datetime|get_datetime:1}
And the challenge is to do away with the prefix. I can't get where the 1
is originating from.
CodePudding user response:
config/app.php
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
You can change your timezone in this config file in Laravel.
However, if you are using simple PHP You should follow :here
You can write this code to your index.php or entry php file. You do not need to echo date_default_timezone_set
this function. It says it changed the timezone and it returns 1. That's why you are seeing 1. You are echoing the result of a function. You do not need to echo that result. Just need to run.