This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Difficult trying to convert a String to a Date

 
Ranch Hand
Posts: 32
  • 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.
 
Ranch Hand
Posts: 210
Eclipse IDE Java
  • 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
 
Bartender
Posts: 563
  • 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.
 
Marshal
Posts: 66158
250
  • 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
  • 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 will suppress my every urge. But not this shameless plug:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!