I would like to print the time in local time in Laravel. If the user create a post it will display the created time on the server. How can I display it in local time ?
You can do this by using javascript. Use following libraries:
Here is the code :
var update_at = 'updated_at;?>'; //set js variable for updated_at
var serverTimezone = 'YOUR SERVER TIME ZONE'; //set js variable for server timezone
var momentJsTimeObj = moment.tz(update_at, serverTimezone); //create moment js time object for server time
var localTimeZone = jstz.determine(); //this will fetch user's timezone
var localTime = momentJsTimeObj.clone().tz(localTimeZone.name()).format(); //convert server time to local time of user
Now you can display local time through js