java获取当前某个时间点
private String getTime(String flag, int times) { String time = new String(); SimpleDateFormat startDf = new SimpleDateFormat("yyyy-MM-dd 00:00:00"); SimpleDateFormat endDf = new SimpleDateFormat("yyyy-MM-dd 23:59:59"); Calendar cal=Calendar.getInstance(); if (times == 2) { cal.add(Calendar.MONTH, -2); //得到前两个月 } else if (times == 6) { cal.add(Calendar.MONTH, -6); //得到前六个月 } else { cal.add(Calendar.MONTH, -1); //得到前一个月 } long l_date = cal.getTimeInMillis(); Date date=new Date(l_date); if (flag.equals("start")) { time = startDf.format(date); } else { time = endDf.format(new Date()); } return time; }
原csdn博客地址:http://write.blog.csdn.net/postlist