如何将1900年12月25日星期二转换成java中的MM/dd/yyyy格式

Pra*_*shi 0 java date

我有日期字符串,如1900年12月25日星期二,我怎么能把它变成MM/dd/yyyy格式.我已经审阅了这个链接,但我的日期格式有一个解决方法.以下是我尝试的但是我得到了一个例外Unparsable date.

String caseDate = "Tuesday , December 25th, 1900";
SimpleDateFormat inputFormat = new SimpleDateFormat("EEEE, MMMM dd Z yyyy");
Date date = inputFormat.parse(caseDate);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = formatter.format(date);
Utils.logtMsg("formattedDate "+formattedDate);
Run Code Online (Sandbox Code Playgroud)

例外

例外:::无法解释的日期:"1900年12月25日星期二"

Poo*_*wal 6

问题是您的输入字符串与您的输入格式不匹配.我改变了格式,工作正常.尝试,

String caseDate = "Tuesday , December 25th, 1900";
        SimpleDateFormat inputFormat = new SimpleDateFormat("EEEE , MMMM dd'th', yyyy");
        Date date = inputFormat.parse(caseDate);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = formatter.format(date);
        System.out.println(formattedDate);
Run Code Online (Sandbox Code Playgroud)