java.text.ParseException: Unparseable date

來源:互聯網
上載者:User

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

 

當用java將字串格式轉換成date類型時,自己定義一個String d = "2010/05/19"時,用語句轉換:

SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );    String ddd = "2009/10/19 00:00:00";    try {   Date d = sdf.parse(ddd);} catch (ParseException e) {   // TODO Auto-generated catch block   e.printStackTrace();}

不會拋出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轉換為資料庫字元集字串。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'顯然不是。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.