import java.text.SimpleDateFormat;
public class time {
public static void main(String[] args) {
String time3;
SimpleDateFormat time2=new SimpleDateFormat("HH"); //提取系统中的小时
int h=Integer.valueOf(time2.format(new Date())); //将小时转换为整数型
if(h<=6 && h>0){
time3="凌晨";
}else{
if(h<=11 && h>6){
time3="上午";
}else{
if(h<=13 && h>11){
time3="中午";
}else{
if(h<=16 && h>13){
time3="下午";
}else{
if(h<=18 && h>16){
time3="傍晚";
}else{
time3="晚上";
}
}
}
}
}
SimpleDateFormat time=new SimpleDateFormat("yyyy年MM月dd月 "+time3+" HH时mm分ss秒");
System.out.println(time.format(new Date()));
}
}
java显示系统时间及判断时间段
于 2019-05-10 17:56:26 首次发布