bakınız. Geçerli saat dilimi ofseti, kullanıcı zamanını hesaplamak için oturumda saklanır. Kullanıcıları zaman dilimi ofsetini oturuma göndermek için bir jquery yayını işlevi oluşturun. Bu benim kod,
default.blade.php
@if($current_time_zone=Session::get('current_time_zone'))@endif
<input type="hidden" id="hd_current_time_zone" value="{{{$current_time_zone}}}">
// For assigning session value to hidden field.
<script type="text/javascript">
$(document).ready(function(){
if($('#hd_current_time_zone').val() ==""){ // Check for hidden field is empty. if is it empty only execute the post function
var current_date = new Date();
curent_zone = -current_date.getTimezoneOffset() * 60;
var token = "{{csrf_token()}}";
$.ajax({
method: "POST",
url: "{{URL::to('ajax/set_current_time_zone/')}}",
data: { '_token':token, curent_zone: curent_zone }
}).done(function(data){
});
}
});
routes.php
Route::post('ajax/set_current_time_zone', array('as' => 'ajaxsetcurrenttimezone','uses' => '[email protected]'));
HomeController olduğunu.php
public function setCurrentTimeZone(){ //To set the current timezone offset in session
$input = Input::all();
if(!empty($input)){
$current_time_zone = Input::get('curent_zone');
Session::put('current_time_zone', $current_time_zone);
}
}
Yardımcılar/helper.php
function niceShort($attr) {
if(Session::has('current_time_zone')){
$current_time_zone = Session::get('current_time_zone');
$utc = strtotime($attr)-date('Z'); // Convert the time zone to GMT 0. If the server time is what ever no problem.
$attr = $utc+$current_time_zone; // Convert the time to local time
$attr = date("Y-m-d H:i:s", $attr);
}
return attr;
}
{{ niceShort($posts->updated_at) }}
index.blade.php Şimdi istemciler saat diliminde yazdırabilirsiniz. Saat dilimi ayar kodu sadece oturum boş olduğunda çalışır.
Sizin temel seçenek 1) olan app.php sayfasında saat dilimi ayarları, saat dilimi hakkında daha iyi bilgi sahibi bu istemci tarafı, Do; cevabınızın bazı JSON'ta UTC zaman damgasını içermesini sağlayın ve yerel saatte bu zaman damgasını görüntülemek için Javascript yazın; 2) Sunucuya, kullanıcının hangi saat diliminde olduğunu (kendi başına biraz zor olabilir) söyleyin ve sunucuyu sunucu tarafında gerçekleştirin. –