Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用DateTimeFormatter和SimpleDataFormat检索格式化日期获取错误_Java_Android_Datetime Format_Simpledateformat_Datetimeformatter - Fatal编程技术网

Java 使用DateTimeFormatter和SimpleDataFormat检索格式化日期获取错误

Java 使用DateTimeFormatter和SimpleDataFormat检索格式化日期获取错误,java,android,datetime-format,simpledateformat,datetimeformatter,Java,Android,Datetime Format,Simpledateformat,Datetimeformatter,这是我的输入日期: String myDate = "2010-02-19"; 我希望从上述日期获得如下输出: Friday, 19-Feb-2010 我尝试了很多方法来获得精确的输出,但还没有成功 以下是我尝试使用DateTimeFormatter和SimpleDateFormat的代码: button.setOnClickListener(new View.OnClickListener() { @Override public voi

这是我的输入日期:

String myDate = "2010-02-19";
我希望从上述日期获得如下输出:

Friday, 19-Feb-2010
我尝试了很多方法来获得精确的输出,但还没有成功

以下是我尝试使用DateTimeFormatter和SimpleDateFormat的代码:

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String myDate = "2010-02-19";
            String strDateTimeFormatter, strSimpleDateFormat;

            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("EEEE, dd-MMM-yyyy", Locale.US);
            LocalDate localDate = LocalDate.parse(myDate, dateTimeFormatter);

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, dd-MMM-yyyy");
            strSimpleDateFormat = simpleDateFormat.format(myDate);

            strDateTimeFormatter = String.valueOf(localDate);

            Log.d("TAG", "DateTimeFormatter: "+strDateTimeFormatter);
            Log.d("TAG", "SimpleDateFormat: "+strSimpleDateFormat);

        }
    });
我从以下行获取
java.time.format.DateTimeParseException:无法在索引0处解析文本“2010-02-19”:

            LocalDate localDate = LocalDate.parse(myDate, dateTimeFormatter);

如何获得我想要的实际输出?

但还没有成功。
奇怪的是,您尝试的输出显示了什么?ParseException,因为
YYYY-MM-dd
无法用
EEEE,dd-MMM-YYYY
解析您正在使用的是java.time、现代java日期和时间API及其
DateTimeFormatter
,那很好。然后不要试图涉及到
SimpleDataFormat
,因为它是一个麻烦且过时的类。不要解析格式化程序,因为您正在解析默认格式的字符串。只是
LocalDate LocalDate=LocalDate.parse(myDate)。之后,
localDate.format(dateTimeFormatter)
将为您提供
2010年2月19日星期五
。返回与myDate相同的内容。@Ole V.V。