java.text.ParseException:无法解析的日期:" 2014年6月4日" (偏移量5) [英] java.text.ParseException: Unparseable date: "2014-06-04" (at offset 5)

查看:1027
本文介绍了java.text.ParseException:无法解析的日期:" 2014年6月4日" (偏移量5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲解析日期为所需的格式,但我每次接收一个例外。 我知道这是很容易实现,但我面临着一些问题,不知道在什么地方:

I want to parse the date into a desired format but i am receiving an exception every time. i know it is easy to implement but i am facing some problem don't know where exactly.:

Exception: java.text.ParseException: Unparseable date: "2014-06-04" (at offset 5)

以下是我的code:

Following is my code:

private String getconvertdate(String date) {
    DateFormat inputFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss",Locale.ENGLISH);
    inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    DateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH);
    Date parsed = null;
    try {
        parsed = inputFormat.parse(date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String outputText = outputFormat.format(parsed);
    return outputText;
}

输入到方法:2014年6月4日

预计产量:06 - 2014年

我跟一些参考。从Stackoverflow.com,但他仍然问题仍然存在。 请帮助。

I have followed some Ref. from Stackoverflow.com, but still he problem persist. Please Help.

推荐答案

您没有时间参加你的字符串: 而该月只有两个字符 替换

You have no time part in your string: and the Month has only two character replace

新的SimpleDateFormat(YYYY-MMM-DD HH:MM:SS,Locale.ENGLISH);

新的SimpleDateFormat(YYYY-MM-DD,Locale.ENGLISH);

这篇关于java.text.ParseException:无法解析的日期:" 2014年6月4日" (偏移量5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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