/**
* 字符串转换为日期
* 2016-2-18
* @param dateString 要转换的字符串 20150102
* @param dateFormat 要转换成的字符串格式 yyyyMMdd
* @return
*/
private static Date StrToDate(String dateString,String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
* 字符串转换为日期
* 2016-2-18
* @param dateString 要转换的字符串 20150102
* @param dateFormat 要转换成的字符串格式 yyyyMMdd
* @return
*/
private static Date StrToDate(String dateString,String dateFormat) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 获取为下个月1号的时间
* @return
*/
private static String nextMonth(){
Date dNow = new Date(); //当前时间
Date dBefore = new Date();
Calendar calendar = Calendar.getInstance(); //得到日历
calendar.setTime(dNow);//把当前时间赋给日历
calendar.add(calendar.MONTH, +1); //设置为前3月
dBefore = calendar.getTime(); //得到前3月的时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式
String defaultStartDate = sdf.format(dBefore); //格式化前3月的时间
String nextMon = defaultStartDate.substring(0,7)+"-01";
return nextMon;
}