| 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: 530
|
|
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: 32830
|
|
|
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 !
|
 |
 |
|
|
subject: Difficult trying to convert a String to a Date
|
|
|