js和C# 判断时间段内早中晚问候语

 function Get_Greetings() {
            var now = new Date();
            var times = now.getHours();
            var whe=parseInt(times);
            if(times>=0 && times<6){return "凌晨"}
            if(times>=6 && times<9){return "早上"}
            if(times>=9 && times<11){return "上午"}
            if(times>=11 && times<13){return "中午"}
            if(times>=13 && times<17){return "下午"}
            if(times>=17 && times<19){return "傍晚"}
            if(times>=19 && times<24){return "晚上"}
        }
  /// <summary>
        /// 获取时间内的问候语
        /// </summary>
        /// <returns></returns>
        public string Get_Greetings()
        {
            string str = "";
            var now = DateTime.Now;
            int times = now.Hour;
            if (times >= 0 && times < 6) { str = "凌晨"; }
            if (times >= 6 && times < 9) { str = "早上"; }
            if (times >= 9 && times < 11) { str = "上午"; }
            if (times >= 11 && times < 13) { str = "中午"; }
            if (times >= 13 && times < 17) { str = "下午"; }
            if (times >= 17 && times < 19) { str = "傍晚"; }
            if (times >= 19 && times < 24) { str = "晚上"; }
            return str;
        }


你可能感兴趣的:(js和C# 判断时间段内早中晚问候语)