How to convert server time to local time in Laravel?

前端 未结 8 1485
失恋的感觉
失恋的感觉 2020-12-30 14:50

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 ?

8条回答
  •  长发绾君心
    2020-12-30 15:26

    Server time should stick with UTC timezone

    In front end, you can use moment.js to render the correct local timezone. I tested this in moment version 2.22.2.

    Simply add Z to the datetime value and moment will render the date to user's local time zone

    moment(dateTimeValue + ' Z'); 
    

提交回复
热议问题