Java 日期字符串String转Date对象

注意事项

格式描述字符串为"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;
    }
发布了14 篇原创文章 · 获赞 3 · 访问量 3495

猜你喜欢

转载自blog.csdn.net/yulianpeng/article/details/92801474