java检查时间更长

java检查时间更长,java,time,java-7,Java,Time,Java 7,嗨,我正在检查当前时间是否是>,比如说14:00。有人知道怎么做吗 这就是我所拥有的: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HH:mm"); 不知何故,我想我现在需要创建一个日期对象并使用这个日期格式 我知道现在的时间是: date= new Date(); 在上面的格式中,它将是returndateFormat.format(date) 因此,任何人都可以提供帮助-非常感谢。(我使用Java 7 btw)

嗨,我正在检查当前时间是否是>,比如说14:00。有人知道怎么做吗

这就是我所拥有的:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HH:mm");
不知何故,我想我现在需要创建一个日期对象并使用这个日期格式

我知道现在的时间是:

date= new Date();
在上面的格式中,它将是return
dateFormat.format(date)

因此,任何人都可以提供帮助-非常感谢。(我使用Java 7 btw)

使用:


要检查一个日期是否早于另一个日期,可以使用日历

Date yourDate                 = new Date();
Date yourDateToCompareAgainst = new Date();
Calendar calendar             = Calendar.getInstance();
calendar.setTime(yourDateToCompareAgainst);
calendar.set(HOUR, 14);

/** You can then check for your condition */
if( calendar.before(yourDate) ) {
}

您可以使用java.util中的日历来实现这一点。希望这有帮助

试试这样的东西

 SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
    Date date = new Date();        
    System.out.println(dateFormat.format(date));
    if(date.after(dateFormat.parse("14:00"))){
        System.out.println("Current time greater than 14.00");
    }

尝试下面的代码,它应该可以工作

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");
}

使用公历希望这有帮助;)


此函数检查字符串次数(12:00:10>12:00:00等)

public静态布尔biggerThanTime(字符串time1,字符串time2){
字符串hhmms1[]=time1.split(“:”);
字符串hhmms2[]=time2.split(“:”);
对于(int i=0;iInteger.parseInt(hhmms2[i]))
返回true;
}
返回false;
}
检查时间是否大于当前时间


Stackoverflow的帖子通常会假装对你遇到的问题提问。毫无疑问,你能详细说明你的问题是什么吗?
 SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
    Date date = new Date();        
    System.out.println(dateFormat.format(date));
    if(date.after(dateFormat.parse("14:00"))){
        System.out.println("Current time greater than 14.00");
    }
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");
}
public Class Time {

    public static void main() {

        Calendar C = new GregorianCalendar();
        int hour = C.get( Calendar.HOUR_OF_DAY );
        int minute = C.get( Calendar.MINUTE );

        if( hour == 14 && minute > 0 )
            System.out.println("time > 14");
    } 

}
public static boolean biggerThanTime(String time1,String time2){
    String hhmmss1[] = time1.split(":");
    String hhmmss2[] = time2.split(":");
    for (int i = 0; i < hhmmss1.length; i++) {
        if(Integer.parseInt(hhmmss1[i])>Integer.parseInt(hhmmss2[i]))
            return true;
    }
    return false;
}
import java.util.*;
import java.time.*;
class one_part
{
public static void main(String []args)
{
LocalTime present=LocalTime.now();
String bf1="07:00:00";
String bf2="10:30:00";
LocalTime bf3 = LocalTime.parse(bf1);
LocalTime bf4 = LocalTime.parse(bf2);
String lunch1="11:30:00";
String lunch2="15:00:00";
LocalTime lunch3=LocalTime.parse(lunch1);
LocalTime lunch4=LocalTime.parse(lunch2);
String dinner1="19:30:00";
String dinner2="22:30:00";
LocalTime dinner3=LocalTime.parse(dinner1);
LocalTime dinner4=LocalTime.parse(dinner2);
if(present.isAfter(bf3) && present.isBefore(bf4))
{
System.out.println("this is breakfast time");
}
else if(present.isAfter(lunch3) && present.isBefore(lunch4))
{
    System.out.println("This is lunch time");
}
else if(present.isAfter(dinner3) && present.isBefore(dinner4))
{
    System.out.println("This is dinner time");
}
else
{
    System.out.println("Restaurent closed");
}
}
}