File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Difficult trying to convert a String to a Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difficult trying to convert a String to a Date" Watch "Difficult trying to convert a String to a Date" New topic
Author

Difficult trying to convert a String to a Date

Cesar Coz
Ranch Hand

Joined: Aug 19, 2010
Posts: 31
I have this String "Fri Dec 04 00:00:00 GMT-05:00 2015" that i get from a web service and i need to parse it to a Date type in this format "YYYY/MM/DD".

I'm having trouble trying to create the Date variable and i wish someone can help me to fin a way to make this convertion. I always have trouble dealing with Date types

Thanks in advance.


Cesar Coz.
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi Cesar,

I had a problem similar to this myself a couple weeks ago, take a look at that thread ---> here! I think you could use the same tips that i got to take care of your problem as well...

here is another link that may help ---> here!




Mike
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Parse the parts of the string you need:

int year = the "YYYY" portion, converted to an integer,
int month = the "Dec" portion converted to an integer, 0 - 11, and
int day = the "04" portion, converted to an integer.

Then set a Calendar instance:



Then you can use the date as a Calendar object or derive from it a Date object, if necessary.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
Surely one of the DateFormat classes, eg SimpleDateFormat, will make that easier.
Cesar Coz
Ranch Hand

Joined: Aug 19, 2010
Posts: 31
Thanks for answering so fast, i got the solution with your help. I solved this way



Hope this can help anyone else with this problem and thanks for the help !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difficult trying to convert a String to a Date
 
Similar Threads
Date Problems
SEVERE: BAD packet signature 200,SEVERE: Caught exception (java.lang.NullPointerException)
sql date parsing
Precision error in converter property of <h:outputText> tag?
How to compare (Hour) with actual new Date() ?