This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
I have a problem about timezone. I want to change timezone without changing the app.php. This setting must work in backend and frontend. any help.
Just struggled with something similar. Here was my final setup. Shared server is running on "MST" as was MySQL by default
Config Files:
app.php
...
'timezone'=>'UTC',
...
database.php
...
'mysql'=>[
'timezone'=>'-00:00',
'driver'=> ...
]
Backend: user can pick their timezone in their individual preferences. I chose 'UTC' for checking that everything was time stamping correctly.
Frontend: Need to convert to users TZ for presentation and forms. Your save process must convert from User TZ to 'UTC'. You can use JS to get the user TZ from browser and AJAX it to your server for saving a session variable or other method of telling server what TZ the user is using.
<script>
tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
window.addEventListener("load", function(){
$.request('onSetTZ', { data: {tz: tz}});
});
</script>
You can convert TZ in twig but I suggest that you handle all TZ conversions in PHP using Carbon for retrieval, presentation and saving because it will be easier if this is done all at the same layer.
Last updated
1-5 of 5