【发布时间】:2014-06-16 12:35:32
【问题描述】:
嘿,我现在有一个问题,我想检查当前时间 say(10;00am) 是否在预设时间之间
框架说(晚上 10:00 - 凌晨 4:00)我该怎么做。
我尝试了一些并不总是满足条件的东西
public class Test {
static int flag;
public static void main(String[] args) {
// TODO Auto-generated method stub
// final Timer timer = new Timer();
// Timer timer2 = new Timer();
SimpleDateFormat parser = new SimpleDateFormat("HH.mm");
Date start = null;
Date end = null;
try {
start = parser.parse("22.00");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
end = parser.parse("8.00");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Date userDate = parser.parse("23.06");
if (userDate.after(start) && userDate.before(end)) {
System.out.println("innnnnnnnnnnn");
} else {
System.out.println("outttttttttt");
}
} catch (ParseException e) {
// Invalid date was entered
}
}
}
【问题讨论】: