Home > Net >  manage timezones JS difference of two hours
manage timezones JS difference of two hours

Time:06-09

frontend side I send axios this date away:

Mon Jun 13 2022 18:29:00 GMT 0200 (Ora legale dell’Europa centrale)

because the backend (laravel 8.x) side saves me the usual one as follows:

2022-06-13 16:29:00

I wish he would save me 18:29 and not 16:29

how can i handle this? i can't install libraries like moment.js

CodePudding user response:

This will likely be due to your app timezone being set to UTC. I personally would recommend storing everything in UTC and converting that for display purposes on the front end.

However, if you must store them in the same format, you'll need to set the timezone in 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', <--- Change this to your timezone eg: Africa/Cairo

Timezones available for GMT 0200

Don't forget to run php artisan config:clear to ensure your timezone configuration changes are being used.

CodePudding user response:

I solved as follows:

    return new Date(year, month - 1, day, hours, minutes, seconds).toString().slice(0, 24);

can you do better?

  • Related