12小时制时间显示
public static void main(String[] args) {
Date date = new Date();//获取当前系统时间
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");//获取十二小时制时间格式对象
String time = sdf.format(date);//将当前时间转化为十二小时制
GregorianCalendar gc = new GregorianCalendar();//获取日历转换对象
gc.setTime(date);//将当前时间转换为GregorianCalendar格式
int AM_PM = gc.get(GregorianCalendar.AM_PM);//获取当前时间的AM/PM属性,返回值是int,AM=0,PM=1
String loginTime = time + (AM_PM == Calendar.PM ? "PM" : "AM");
System.out.println(loginTime);
}