我得到了错误java.text.ParseException:不可解析的日期为空

我得到了错误java.text.ParseException:不可解析的日期为空,java,date,calendar,Java,Date,Calendar,我希望日期格式为yyyy-MM-dd。我的代码为: Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd", Locale.ENGLISH); cal.setTime(sdf.parse(row.getCell(67).toString())); 单元格中的值为:06/

我希望日期格式为yyyy-MM-dd。我的代码为:

       Calendar cal = Calendar.getInstance();
              SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd", Locale.ENGLISH);
              cal.setTime(sdf.parse(row.getCell(67).toString()));
单元格中的值为:06/02/2020 但是,我得到的错误是:

java.text.ParseException: Unparseable date: "null"
    at java.text.DateFormat.parse(Unknown Source) ~[na:1.8.0_251]
谢谢你的帮助

但是,我希望日期格式为yyyy-MM-dd

这是完整的代码:

if(row.getCell(67).equals("null"))
                  {

                      Calendar cal = Calendar.getInstance();
                      cal.set(Calendar.YEAR, 1988);
                      cal.set(Calendar.MONTH, Calendar.JUNE);
                      cal.set(Calendar.DAY_OF_MONTH, 1);
                      Date dateRepresentation = cal.getTime();
                      rfx.setRv_rc_date(dateRepresentation);
                  }
                  else
                  {

                      Calendar cal = Calendar.getInstance();
                      SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd", Locale.ENGLISH);
                      cal.setTime(sdf.parse(row.getCell(67).toString()));
                      System.out.println("******************************************************");
                      System.out.println(cal);
                      System.out.println("*******************************************************");

                     

                  }
                  

我得到了这个错误:java.text.ParseException:不可解析的日期:“2020年1月30日”

在谷歌搜索这个日期时,我发现它在
法语
语言环境中,而你使用的是
语言环境。英语

如下所示,改用
Locale.FRENCH
来消除错误

SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd", Locale.FRENCH);
演示:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    public static void main(String[] args) throws ParseException {
        // Input format
        SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRENCH);
        Date date = inputFormat.parse("30-janv.-2020");

        // Output format
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(outputFormat.format(date));
    }
}
2020-01-30
2020-01-30
输出:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    public static void main(String[] args) throws ParseException {
        // Input format
        SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRENCH);
        Date date = inputFormat.parse("30-janv.-2020");

        // Output format
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(outputFormat.format(date));
    }
}
2020-01-30
2020-01-30
但是,我建议您停止使用过时的日期-时间API,并切换到,如下所示:

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy", Locale.FRENCH);
        LocalDate date = LocalDate.parse("30-janv.-2020", formatter);
        System.out.println(date);
    }
}
输出:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    public static void main(String[] args) throws ParseException {
        // Input format
        SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.FRENCH);
        Date date = inputFormat.parse("30-janv.-2020");

        // Output format
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(outputFormat.format(date));
    }
}
2020-01-30
2020-01-30

请注意,我没有为此输出定义任何格式化程序,因为已返回所需格式的字符串。

请检查您的数据并调试您的代码,对我来说,这看起来就像
行.getCell(67).toString()
返回
null
以及
sdf
中的“-”在哪里,此外,请尝试从
java.util
中避免过时的datetime API,改用
java.time
。请再次检查答案我刚刚更新了我收到了以下错误:java.text.ParseException:不可解析的日期:“2020年1月30日”