java中时间的获取2
/**
* 获取数据库操作记录时间
*/
public static String getOpreateDbTime() {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(new Date().getTime());
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
return dateFormat.format(c.getTime());
} /**
* 获取当天日期
*/
public static String getOpreateDay() {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(new Date().getTime());
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
return dateFormat.format(c.getTime());
} /**
* 推算出两者之间的每一天的每一天
*/ public static List<String> geteveryDayBetweenDayLine(String maxDay,String nowDay,String sourcei){
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
List<String> list = new ArrayList<String>();
try {
Date date2;
if(sourcei.equals("rdcj.YCSY_OILDEV_BASEDATAINFO")){
date2 = new SimpleDateFormat("yyyyMM").parse(maxDay);
}else if(sourcei.equals("rdcj.YCSY_OGASRESERVOIR_BASEINFO")){
date2 = new SimpleDateFormat("MM/dd/yyyy").parse(maxDay);
}else{
date2 = new SimpleDateFormat("yyyy-MM-dd").parse(maxDay);
}
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(nowDay);
Calendar cal = Calendar.getInstance();
cal.setTime(date2);
while(cal.getTime().compareTo(date1)<=0){
cal.add(Calendar.DAY_OF_MONTH,1);
list.add(sdf.format(cal.getTime()));
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}