java检查时间是更大的时间 [英] java check time is greater time
本文介绍了java检查时间是更大的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查currentime是否为>,例如14:00.有人知道该怎么做吗?
Hi I'm trying to check if the currentime is > , say, 14:00. Does anyone know how to do this?
这就是我所拥有的:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HH:mm");
以某种方式我想我现在需要创建一个Date对象并使用此dateformat吗?
Somehow I guess I need to now create a Date object and use this dateformat?
我知道当前时间是
date= new Date();
,并以上述格式返回dateFormat.format(date);
任何人都可以提供帮助-非常感谢. (上午使用Java 7 btw)
So can anyone help - much appreciated. (am using Java 7 btw)
推荐答案
尝试下面的代码,它应该可以工作.
Try below code, it should work.
Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm") ;
dateFormat.format(date);
System.out.println(dateFormat.format(date));
if(dateFormat.parse(dateFormat.format(date)).after(dateFormat.parse("12:07")))
{
System.out.println("Current time is greater than 12.07");
}else{
System.out.println("Current time is less than 12.07");
}
这篇关于java检查时间是更大的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文