How to convert server time to local time in Laravel?

前端 未结 8 1504
失恋的感觉
失恋的感觉 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:51

    I found a solution to convert time to local time by using session. The current time zone offset will store on session to calculate users time. Create a jquery post function to post users timezone offset to session. This is my code,

    default.blade.php

    @if($current_time_zone=Session::get('current_time_zone'))@endif
    
    // For assigning session value to hidden field. 
    
    
    
                                     
                  
提交回复
热议问题