java.lang.IllegalArgumentException: Illegal pattern character 'o'

 http://stackoverflow.com/questions/4993132/getting-java-lang-illegalargumentexception-illegal-pattern-character-o-while

wanted to convert from string to java.util.Date. for the same purpose I used following code,

String timeStamp = "Mon Feb 14 18:15:39 IST 2011"; 
DateFormat formatter = new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy"); 
Date ts = (Date)formatter.parse(timeStamp); 

The format given to SimpleDateFormat() is format of java.util.Date. When you convert util's Date to string it comes in this format('dow mon dd hh:mm:ss zzz yyyy'). But when I execute code, It gives me Exception. I Don't know what exactly I needed to do to get rid of this problem. I am posting the part of StackTrace of exception. If anybody knows the solution,

java.lang.IllegalArgumentException: Illegal pattern character 'o' at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769) at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576) at java.text.SimpleDateFormat.(SimpleDateFormat.java:501) at java.text.SimpleDateFormat.(SimpleDateFormat.java:476) Thank you in advance.

 

 

====

Try this instead:

DateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy"); 

E is used for "Day in Week" as text, M is the month name.

 
Yes, this format is correct. Actually from java docs I got that format for util's Date.toString() function. Thank you very much. –  Sagar Feb 14 '11 at 14:26
 
Actually, it should be HH (hours in 0..23) and not hh (hours in 1..12. The documentation of Date.toString is quite confusing, I'm just filing a bug report about this. –  Paŭlo Ebermann Feb 14 '11 at 15:27

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值