今天遇到 默认在jsp页面显示 当月的数据, 查询条件限制 有时间 ,
以下是如何获得 当月第一天 00:00:00的数据
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
Date da = new Date(date.getYear(),date.getMonth(),01);
startTime=Timestamp.valueOf(df1.format(da));
经过以上代码:
如获得这个月的第一天的 时间为:
2009-12-02 00:00:00
//获取下月
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, 1);
Date theDate = calendar.getTime();
String strDateDay = new SimpleDateFormat("MM").format(theDate);
int int_strDateDay = Integer.parseInt(strDateDay);
String ttt = new SimpleDateFormat("yyyy-MM-dd").format(theDate);
String worktime = new SimpleDateFormat("yyyyMM").format(theDate);
//下月的第一天
gc.setTime(theDate);
gc.set(Calendar.DAY_OF_MONTH, 1);
String day_first_nextM = df.format(gc.getTime());
//下月的最后一天
calendar.add( cal.MONTH,1 );
calendar.set(cal.DATE,1);
calendar.add(cal.DATE,-1);
String day_end_nextM=df.format(calendar.getTime());
//当前月的第一天
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:MM:DD");
GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
gc.set(Calendar.DAY_OF_MONTH, 1);
String day_first = df.format(gc.getTime());
System.out.println(day_first);