Java/Android - 将 GMT 时间字符串转换为本地时间
2022-09-03 18:03:35
						好的,所以我有一个字符串,说“星期二五月21 14:32:00 GMT 2012”我想将此字符串转换为本地时间,格式为2012年5月21日下午2:32。我尝试了SimpleDateFormat(“MM dd, yyyy hh:mm a”).parse(),但它抛出了一个异常。那我该怎么办呢?
例外是“未报告的异常 java.text.ParseException;必须被抓住或被宣布被扔掉。
在行中Date date = inputFormat.parse(inputText);
我在TextMate上运行的代码:
public class test{
    public static void main(String arg[]) {
        String inputText = "Tue May 22 14:52:00 GMT 2012";
        SimpleDateFormat inputFormat = new SimpleDateFormat(
            "EEE MMM dd HH:mm:ss 'GMT' yyyy", Locale.US);
        inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
        SimpleDateFormat out = new SimpleDateFormat("MMM dd, yyyy h:mm a");
        Date date = inputFormat.parse(inputText);
        String output = out.format(date);
       System.out.println(output);
    }
}