小程序-判断一天的不同时间段显示不同的内容

摘要

好吧,判断一天的不同时间段显示不同的内容又是在我的项目中的一个需求,没办法呀,容易忘,还是写着吧

需求:1.把一天分为3个时间段,5:00-11:00    11:00-15:00   15:00-5:00

           2.不同的时间段顶部背景色颜色不同

onLoad:function(){

         var time = parseInt(new Data().getHours());    //返回小时数

          var times = 1;

          if(5 < time && time < 11){

               times = 1;

               console.log("早")

          }else if (11 <= time && time <15){

              times = 2;

               console.log("中")

          }else{

                times = 3;

                console.log("晚")

          }

          var that = this;

          switch (times){

                 case 1:

                           that.setData({ });

                          wx.setNavigationBarColor({      //用于动态设置手机顶部的背景颜色

                                   frontColor:"#ffffff",        //设置16进制的颜色值哦   必须写的哦

                                   backgroundColor:"#ff0000"

                          });

                          break;

                 case 2:

                          that.setData({ });

                          wx.setNavigationBarColor({

                                   frontColor:"#ffffff",

                                   backgroundColor:"#ff0304"

                          });

                          break;

                default:

                             that.setData({ });

                             wx.setNavigationBarColor({

                                        frontColor:"#ffffff",

                                        backgroundColor:"#ff0304"

                              });

                             break;

           }

}

原文地址:https://www.cnblogs.com/liuqingxia/p/7722694.html