• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difficult trying to convert a String to a Date

 
Cesar Coz
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 563
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely one of the DateFormat classes, eg SimpleDateFormat, will make that easier.
 
Cesar Coz
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic