java : How can I cast Date from "Thu May 01 00:00:00 WEST 2014 " to "2014-01-05 00:00:00.0"

Posted by lilyana on Stack Overflow See other posts from Stack Overflow or by lilyana
Published on 2014-05-29T09:21:44Z Indexed on 2014/05/29 9:24 UTC
Read the original article Hit count: 281

Filed under:
|
|

How can I want to cast Date from "Thu May 01 00:00:00 WEST 2014 " to "2014-01-05 00:00:00.0"

I try with this code :

SimpleDateFormat toFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
        String dateStr = getDtdebut().toString();
        Date date = new Date();
        try {
            date = toFormat.parse(dateStr);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

but i have this error :

java.text.ParseException: Unparseable date: "Thu May 01 00:00:00 WEST 2014"
at java.text.DateFormat.parse(Unknown Source)
at ensa.pfe.action.GestionOperations.filtre(GestionOperations.java:386)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
..........

© Stack Overflow or respective owner

Related posts about java

Related posts about date