注意事项
格式描述字符串为"yyyy-MM-dd"
特别提醒:月份描述字符串为大写的M。
import java.text.SimpleDateFormat;
import java.util.Date;
public Date dateFromString(String dateStr){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Date date = new Date();
try {
return simpleDateFormat.parse(dateStr);
} catch (Exception e){
logger.error(e);
}
return date;
}