java中时间的获取(二)

java中时间的获取2

 1     /**
 2      * 获取数据库操作记录时间
 3      */
 4     public static String getOpreateDbTime() {
 5         Calendar c = Calendar.getInstance();
 6         c.setTimeInMillis(new Date().getTime());
 7         SimpleDateFormat dateFormat = new SimpleDateFormat(
 8                 "yyyy-MM-dd HH:mm:ss");
 9         return dateFormat.format(c.getTime());
10     }
11     
12     /**
13      * 获取当天日期
14      */
15     public static String getOpreateDay() {
16         Calendar c = Calendar.getInstance();
17         c.setTimeInMillis(new Date().getTime());
18         SimpleDateFormat dateFormat = new SimpleDateFormat(
19                 "yyyy-MM-dd");
20         return dateFormat.format(c.getTime());
21     }
22     
23     /**
24      * 推算出两者之间的每一天的每一天
25      */
26     
27     public static  List<String> geteveryDayBetweenDayLine(String maxDay,String nowDay,String sourcei){
28         SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy-MM-dd" );
29         List<String> list = new ArrayList<String>();
30         try {
31             Date date2;
32             if(sourcei.equals("rdcj.YCSY_OILDEV_BASEDATAINFO")){
33                 date2 = new SimpleDateFormat("yyyyMM").parse(maxDay);
34             }else if(sourcei.equals("rdcj.YCSY_OGASRESERVOIR_BASEINFO")){
35                 date2 = new SimpleDateFormat("MM/dd/yyyy").parse(maxDay);
36             }else{
37                 date2 = new SimpleDateFormat("yyyy-MM-dd").parse(maxDay);
38             }
39             Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(nowDay);
40             Calendar cal = Calendar.getInstance();
41             cal.setTime(date2); 
42             while(cal.getTime().compareTo(date1)<=0){ 
43             cal.add(Calendar.DAY_OF_MONTH,1);
44              list.add(sdf.format(cal.getTime()));
45             }
46         } catch (ParseException e) {
47             // TODO Auto-generated catch block
48             e.printStackTrace();
49         }
50         return list;
51     }
原文地址:https://www.cnblogs.com/tian830937/p/4431942.html