Java Calendar 获取上下午
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = sdf.parse(yourdate);
Calendar cal=Calendar.getInstance();
if(null!=date){
cal.setTime(date);
if (Calendar.AM == cal.get(Calendar.AM_PM)) {
return "上午";
}
}
本文介绍了一种使用Java的Calendar类来判断并返回给定日期属于上午还是下午的方法。通过SimpleDateFormat格式化字符串得到特定格式的日期,然后利用Calendar实例化对象,并设置时间,最后通过get方法获取上午或下午的标识。
657

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



