我有一個(gè)插件,可以為用戶提供要預(yù)訂的 time_slots。問題在于,無論您身在何處,您都會(huì)看到 utc-4 中的小時(shí)數(shù)。我希望客戶看到他們的時(shí)區(qū)反映的時(shí)間我是一個(gè)巨大的 js/php newb,但我想我需要一個(gè)小函數(shù),在打印之前將 $slot 轉(zhuǎn)換為用戶時(shí)間while (strtotime($date_from) < strtotime($end_date)) { $cdiv++; $day_num_of_week = date('N', strtotime($date_from)); ?> <h3><?php echo date('l, j F, Y', strtotime($date_from))?> - <?php echo $day_num_of_week?></h3> ?> <div class="bup-time-slots-divisor" id="bup-time-sl-div-<?php echo $cdiv?>"> <?php //get available slots for this date $time_slots = $this->get_time_slot_public_for_staff($day_num_of_week, $staff_id, $b_category, $time_format); $cdiv_range = 0 ; foreach($time_slots as $slot) { $cdiv_range++; ?> <li id="bup-time-slot-hour-range-<?php echo $cdiv?>-<?php echo $cdiv_range?>"> <span class="bup-timeslot-time"><i class="fa fa-clock-o"></i> <?php echo $slot['from'].' – '.$slot['to']?></span> <span class="bup-timeslot-count"><span class="spots-available">1 time slot available</span></span> <span class="bup-timeslot-people"> <button class="new-appt bup-button bup-btn-book-app" bup-data-date="<?php echo date('Y-m-d', strtotime($date_from))?>" bup-data-timeslot="<?php echo $b_category.'-'.$staff_id?>"> <span class="button-timeslot"></span><span class="bup-button-text"> <?php _e('Book Appointment','bookingup')?></span></button> </span> </li> <?php } //end for each time slots ?></div><?php //increase date $date_from = date ("Y-m-d", strtotime("+1 day", strtotime($date_from))); } ?></ul>我希望用戶根據(jù)他們的時(shí)區(qū)查看時(shí)間段,澳大利亞的 ej 是一天后,或者 x 城市的 2 小時(shí)前任何幫助都會(huì)很棒?。?
1 回答

慕標(biāo)5832272
TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
你可以這樣做:
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
并將變量 dateTime 放入您想要的標(biāo)記 HTML 中,如下所示:
document.getElementById('idElement').innerHTML = dateTime;
你的標(biāo)簽 HTML 是這樣的:
<div id='idElement'>Here you will find your input (time)</div>
- 1 回答
- 0 關(guān)注
- 184 瀏覽
添加回答
舉報(bào)
0/150
提交
取消