我想比较系统时间和手动给定的时间,这个程序不满足条件。我怎样才能以 24 小时格式执行此操作。
Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
String time = hour + ":" + minute + ":" + second + " " + am_pm ;
String time1 = 12 + ":" + 40 + ":" + 00 + " " + "PM";
if(time==time1)
{
display(time);
}
else
{
display(time);
}
我必须在 android 应用程序中执行此操作。所以请帮助我。
最佳答案
这给出了小时(0-23):
int hour = calendar.get(Calendar.HOUR_OF_DAY);
关于java - 使用java比较两个TIME变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5713781/