//判断当前是上午中午下午
int getTimeType(Date time) {
SimpleDateFormat df = new SimpleDateFormat("HH");
String str = df.format(time);
int a = Integer.parseInt(str);
//上午
if (a >= 0 && a <= 9) {
return 1;
}
//中午
if (a > 12 && a <= 15) {
return 2;
}
//下午
if (a > 18 && a <= 24) {
return 3;
}
return 0;
}
判读当前时间是上午中午下午
最新推荐文章于 2026-07-05 13:17:34 发布
本文介绍了一个Java函数,用于根据24小时制的时间戳判断当前时刻属于上午、中午还是下午。通过 SimpleDateFormat 对时间进行格式化,然后转换为整数进行判断。

1810

被折叠的 条评论
为什么被折叠?



