class="java" name="code"> /**取当前时间30分钟前的*/ Date date = new Date(); long time = (date.getTime()/1000)-60*30; date.setTime(time*1000); SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm"); String beforeDate = formatter.format(date); Date date1 = new Date(); /**取当前时间30分钟后的*/ long time1 = (date1.getTime()/1000)+60*30; date1.setTime(time1*1000); String afterDate = formatter.format(date1); /**hql语句中须对javabean取出的日期字段进行to_char,因为to_date中第一个参数是字符串,javabean取出的是日期类型*/ String hql = "from OpenMeetingCourse where to_date(to_char(beginTime, 'yyyy-mm-dd hh24:mi')," + "'yyyy-mm-dd hh24:mi') >=to_date('" + beforeDate + "','yyyy-mm-dd hh24:mi') and " + "to_date(to_char(beginTime, 'yyyy-mm-dd hh24:mi')," + "'yyyy-mm-dd hh24:mi')<=to_date('" + afterDate + "','yyyy-mm-dd hh24:mi') order by idCourse desc";