JSP 后台部分代码不能运行 MVC模式下的开发

XX的小石头 2012-12-28 11:11:57
我从前台传一个HH:mm格式的时间到这个方法里,代码运行到if(endtime1.getHours()>=begin.getHours()){之后就跳到flag=false那句了,这个判断条件是得到true的,是不是因为我定义的时间格式不相同的原因呢?求高手解答啊!!万分感谢!!

代码如下:

public boolean samedate(Place_user samedate) throws Exception {
// TODO Auto-generated method stub
boolean flag=false;
PreparedStatement psmt=null;
String placebegin=null;
Date begin=null;
SimpleDateFormat time1=new SimpleDateFormat("MM-dd,HH:mm");
SimpleDateFormat time2=new SimpleDateFormat("HH:mm");
//当前时间
String nowtime=time1.format(new Date());
Date nowtime1=time1.parse(nowtime);
//使用结束时间
String endtime=samedate.getEndtime();
Date endtime1=time2.parse(endtime);
String sql="select placebegin from place_date where placeno=?";
try{
psmt=this.conn.prepareStatement(sql);
psmt.setInt(1, samedate.getPlaceno());
ResultSet rs=psmt.executeQuery();
if(rs.next()){
placebegin=(rs.getString(1));
}
begin=time1.parse(placebegin);
//时间段判断
if( nowtime1.getDate()==begin.getDate()){
// if(endtime1.getHours()>=begin.getHours()){
// flag=true;
}else{
flag=false;

}
}
}catch(Exception e){
throw e;
}finally{
try{
psmt.close();
}catch(Exception e){
throw e;
}
}
return flag;
}
...全文
120 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
XX的小石头 2012-12-29
  • 打赏
  • 举报
回复
已经解决了,是时间格式错了
General-M 2012-12-29
  • 打赏
  • 举报
回复
先在控制台把他们的值输出来看看,是不是格式问题,看看gethour后的值分别是什么

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧