• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Difficult trying to convert a String to a Date

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 75620
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Yeah, but is it art? What do you think tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic