hibernate 有关根据时间查询记录的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 11:40:50
我现在用hibernate连接的是SQL Server 2000数据库,我要查询时间为今天的数据,写了
Query query = session.createQuery("from TTask where c_date=:now");
然后
query.setDate("now",new Date());
就是查不出数据,请各位朋友帮我出出注意啊,小弟在此焦急地等。
那要怎么查啊,我就是这个不知道啊。

new Date()处理的日期是:Wed Aug 01 16:11:23 CST 2007这种形式的,你数据库存储的是这种形式的吗?再说他精确到秒,你也不可能从数据库中找到此条记录.

你数据库里面的日期形式是怎样的?
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest{
public static void main(String[] args){
Date myDate=new Date(System.currentTimeMillis());
System.out.println(myDate.toString());
SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy/MM/DD HH:mm:ss");
System.out.println(sDateFormat.format(myDate));
}
}