将字符串转换为指定格式的日期类型 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM")Date date = dateFormat.parse(str);此方法会抛出异常 还要try catch 下