使用 js 和 php 根据 wordpress 上的时区显示时间

我有一个插件,可以为用户提供要预订的 time_slots。问题在于,无论您身在何处,您都会看到 utc-4 中的小时数。我希望客户看到他们的时区反映的时间


我是一个巨大的 js/php newb,但我想我需要一个小函数,在打印之前将 $slot 转换为用户时间


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>&nbsp;&nbsp;<?php echo $slot['from'].' &ndash; '.$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>

我希望用户根据他们的时区查看时间段,澳大利亚的 ej 是一天后,或者 x 城市的 2 小时前


任何帮助都会很棒!!


手掌心
浏览 169回答 1
1回答

慕标5832272

你可以这样做: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 放入您想要的标记 HTML 中,如下所示:document.getElementById('idElement').innerHTML = dateTime;你的标签 HTML 是这样的:&nbsp;<div id='idElement'>Here you will find your input (time)</div>
打开App,查看更多内容
随时随地看视频慕课网APP