Android 无法分析日期

Android 无法分析日期,android,date,format,Android,Date,Format,我正在尝试将android中的以下日期解析为设备本地时间。 日期为2016年4月7日星期四18:26:42 GMT+05:30。我想以任何其他格式获取此日期,例如MM dd yyyy 以下是我尝试过的: SimpleDateFormat inputFormat = new SimpleDateFormat( "EEE MMM dd HH:mm:ss 'GMT' Z yyyy", Locale.US); inputFormat.setTimeZone

我正在尝试将android中的以下日期解析为设备本地时间。 日期为2016年4月7日星期四18:26:42 GMT+05:30。我想以任何其他格式获取此日期,例如MM dd yyyy

以下是我尝试过的:

SimpleDateFormat inputFormat = new SimpleDateFormat(
                "EEE MMM dd HH:mm:ss 'GMT' Z yyyy", Locale.US);
        inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));

        SimpleDateFormat outputFormat = new SimpleDateFormat("MMM dd, yyyy h:mm a");

        Date date = inputFormat.parse("Thu Apr 07 18:26:42 GMT+05:30 2016");
        String outputText = outputFormat.format(date);
        WriteLog.Print("outputText" + outputText);
请告诉我我做错了什么。上面的代码给了我一个例外,说是不可解析的日期


谢谢

您的问题是,
输入格式中有一点空白

SimpleDateFormat inputFormat = new SimpleDateFormat(
    "EEE MMM dd HH:mm:ss 'GMT' Z yyyy", Locale.US);
相反,您需要:

SimpleDateFormat inputFormat = new SimpleDateFormat(
    "EEE MMM dd HH:mm:ss 'GMT'Z yyyy", Locale.US);

如果您使用
EEE MMM dd HH:mm:ss'GMT'Z yyyy
代替
inputFormat
,会发生什么情况?我觉得空格可能不匹配。您的
inputFormat
section@Knossos非常感谢你。是的,空白是个问题。我会写下来作为答案。