C#怎么判断当前服务器时间是上午还是下午?

如果是Asp。net就用js代码:///////////////////////////

<script language="javaScript">

now = new Date(),hour = now.getHours()

if(hour < 6){document.write("凌晨好!")}

else if (hour < 9){document.write("早上好!")}

else if (hour < 12){document.write("上午好!")}

else if (hour < 14){document.write("中午好!")}

else if (hour < 17){document.write("下午好!")}

else if (hour < 19){document.write("傍晚好!")}

else if (hour < 22){document.write("晚上好!")}

else {document.write("夜里好!")}

</script>

如果是winform就用这些代码://////////////////////////////

Console.WriteLine(MorningOrNoon(DateTime.Now) + "好!");

private string MorningOrNoon(DateTime dt)

{

DateTime dt1 = new DateTime(2009, 5, 6, 8, 0, 0);

DateTime dt2 = new DateTime(2009, 5, 6, 12, 0, 0);

DateTime dt3 = new DateTime(2009, 5, 6, 18, 0, 0); ;

if (dt.TimeOfDay > dt1.TimeOfDay && dt.TimeOfDay < dt2.TimeOfDay)

return "早上";

if (dt.TimeOfDay > dt2.TimeOfDay && dt.TimeOfDay < dt3.TimeOfDay)

return "下午";

else

return "其他时间";

}