vue前端工程传到java后端的日期格式为2019-06-03T16:00:00.000Z,需要将此格式转换为2019-06-03 16:00:00

此问题是属于单纯的日期格式问题,直接上日期格式转换的代码:(转换后的日期可以直接作为条件使用mybatis进行条件查询)

public class DateUtil{

/**
     * 将2019-06-03T16:00:00.000Z日期格式转换为2019-06-03 16:00:00格式
     * @param oldDateStr
     * @return
     */
    public static Date transferDateFormat(String oldDateStr) {
    	if (StringUtils.isBlank(oldDateStr)){
            return null;
        }
    	Date date = null;
        Date date1 = null;
        String dateStr = null;
        try {
        	dateStr = oldDateStr.replace("Z", " UTC");//是空格+UTC
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
            date1 = df.parse(dateStr);
            SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
            date = df1.parse(date1.toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

 

你可能感兴趣的:(时间格式转换,Mysql,数据处理,开发遇到的问题,Date参数类型处理)