从字符串转换为日期抛出不可稀释的日期异常 [英] Convert from String to Date throws Unparseable date exception

查看:235
本文介绍了从字符串转换为日期抛出不可稀释的日期异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个日期转换为字符串,但我有一些问题。我的代码是这样的:

I want to convert a Date to a String but I have some problems. My code is this:

SimpleDateFormat formato = new SimpleDateFormat(
            "EEE MMM dd HH:mm:ss z yyyy");

    String hacer = "Fri Nov 01 10:30:02 PDT 2013";
    Date test = null;
    test = formato.parse( hacer);
    System.out.println("prueba===>" + test);

但没有什么是错误的日食显示我这个错误:

But nothing something is wrong eclipse shows me this error:

Unparseable date: "Fri Nov 01 10:30:02 PDT 2013"
at java.text.DateFormat.parse(Unknown Source)

一些帮助?

推荐答案

p>您的默认语言环境可能不支持MMM中的英语月份。例如在波兰MMM支持styczeń而不是Jan或January

Probably your default locale doesn't support English months in MMM. For example in Poland MMM supports "styczeń" but not "Jan" or "January"

要更改此在 SimpleDateFormat 您需要设置支持以英文写的月份的区域设置,例如

To change this In SimpleDateFormat you need to set locale which supports months written in English, for example

new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);

这篇关于从字符串转换为日期抛出不可稀释的日期异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆