public class date {
public static void main(String[] args) {
//日期时间,Date是一个时间类,d.getHours()是获取当前时间
Date d =new Date();
int a=d.getHours();
if (a>=0 && a<6){
System.out.println("凌晨好");
} else if (a>=6 && a<8) {
System.out.println("早上好");
} else if (a >= 8 && a < 12) {
System.out.println("上午好");
} else if (a >= 12 && a < 14) {
System.out.println("中午好");
} else if (a > 14 && a < 18) {
System.out.println("下午好");
}else if (a>=18 && a <20){
System.out.println("晚上好");
} else if (a>=20 &&a <23) {
System.out.println("夜里好");
} else if (a>=23 &&a <24) {
System.out.println("午夜好");
}
}
}
根据系统时间编写实现分时问候(Java代码)
于 2023-07-06 20:03:53 首次发布