java.text.ParseException: Unparseable date

来源:互联网 发布:python调用r语言 编辑:程序博客网 时间:2024/05/17 05:14

转自:http://hi.baidu.com/%BE%A9%B3%C7%BD%AD%D1%A9/blog/item/5bc274dbec37fc2710df9b61.html 

 

当用java将字符串格式转换成date类型时,自己定义一个String d = "2010/05/19"时,用语句转换:

[java] view plain copy
  1. SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );  
  2.     String ddd = "2009/10/19 00:00:00";  
  3.     try {  
  4.    Date d = sdf.parse(ddd);  
  5. catch (ParseException e) {  
  6.    // TODO Auto-generated catch block  
  7.    e.printStackTrace();  
  8. }  

不会抛出java.text.ParseException: Unparseable date: "2009/10/19 00:00:00"
at java.text.DateFormat.parse(DateFormat.java:337)
at com.come.Dates.main(Dates.java:14)
异常

但是当字符串是用String startDate = request.getParameter("startDate");传过来时会报异常

解决方法:一:Date startReportDate = sdf.parse(startDate.toString());对字符串进行toString 不明白为什么

二:Date start = (Date)sdf.parseObject(startDate);

可以解决

我的问题看过上面的文章后没有解决

另附oracle 转换  解决

to_char()函数的形式有三种:1.  to_char(char)的作用是:将NCHAR或NVARCHAR2或CLOB或NCLOB类型的参数char转换为数据库<a target=_blank target="_blank" class="inner-link" href="http://zhidao.baidu.com/search?word=%E5%AD%97%E7%AC%A6%E9%9B%86&fr=qb_search_exp" rel="nofollow" style="color: rgb(202, 0, 0); text-decoration: none;">字符集</a>字符串。2.  to_char(date[,fmt][,'nlsparam'])的作用是:将日期date按指定格式转换为VARCHAR2类型字符串;因sysdate本身是日期型,它的作用是返回当前系统的日期时间,所以用to_char(sysdate,'fmdd mouth yyyy')是正确的。即:select to_char(sysdate,'fmdd month yyyy') ddddd from dual;3.  to_char(num[,fmt][,'nlsparam'])的作用是:将数值num按指定格式转换为VARCHAR2类型字符串。to_date(char[,fmt][,'nlsparam'])的第一个参数char必须是符合特定格式的字符串。而'ddddd'显然不是。
0 0
原创粉丝点击