这是我的输入日期:
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: Text '2010-02-19' could not be parsed at index 0
从以下行中得到:
LocalDate localDate = LocalDate.parse(myDate, dateTimeFormatter);
如何获得我想要的实际输出?