系统中将Calendar生产的时间转换为了double类型保存到数据库中。因此在查询时间时需要对传入的日期进行转换。查询具体某一天的数据,思路是查询当天0点到23点的数据。
//时间精确到毫秒,保存数据的时候扩大了1000倍
//获取指定日期0点
public static double todayFirstDate(int year,int month,int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month);
calendar.set(Calendar.DAY_OF_MONTH,day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis()/1000;
}
//获取指定日期23点
public static double todayLastDate(int year,int month,int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month);
calendar.set(Calendar.DAY_OF_MONTH,day);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
return calendar.getTimeInMillis()/1000;
}