今天进行技术分享的是 @ellen 精彩内容如下:
@ellen 分享了一个不同时间时区显示不同时间和白天黑夜状态图片的JS,如下:
<div class="time"> <ul> <li> <div class="img"> <?php date_default_timezone_set('PRC'); //设定时区,PRC就是天朝 $hour = date('H'); if($hour <= 18 && $hour >= 6){ echo '<img src="/wp-content/themes/uniontradecn/images/sun.png" alt="sun" class="img-responsive">'; }else{ echo '<img class="moon img-responsive" src="/wp-content/themes/uniontradecn/images/moon.png" alt="moon" >'; } ?> </div> <?php echo '<h2 id="bjdtime"></h2> '; ?> <p>Beijing time</p> </li> <li> <div class="img"> <?php function_exists(date_default_timezone_set); date_default_timezone_set("Etc/GMT"); date_default_timezone_set("Etc/GMT-2"); $hour = date('H'); if($hour <= 18 && $hour >= 6){ echo '<img src="/wp-content/themes/uniontradecn/images/sun.png" alt="sun" class="img-responsive">'; }else{ echo '<img class="moon img-responsive" src="/wp-content/themes/uniontradecn/images/moon.png" alt="moon" >'; } ?> </div> <?php echo '<h2 id="nytime"></h2> '; ?> <p>Ankara time</p> </li> </ul>