Wed Jul 22 00:00:00 CST 2020 java转成指定日期格式的字符串

Wed Jul 22 00:00:00 CST 2020 格林尼治时间,一般都是excel导入的时候,会变成这种格式

例:

/**将格林尼治格式的日期转为yyyy-MM-dd格式*/
String str = "Wed Jul 22 00:00:00 CST 2020" ;
checkDate(str);

public static String checkDate(String str){
    String format1 = null;
    try {
        SimpleDateFormat format = new SimpleDateFormat(yyyy-MM-dd);
        Date date = new Date(str);
        format1 = format.format(date);
    } catch (Exception e) {
        throw  new BusinessException("日期格式错误!请以"+yyyy-mm-dd+"格式填写日期");
    }
    return format1;
}

你可能感兴趣的:(java)