• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String to Date - JDK 1.4.2

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've always hated date manipulation.

I have a list of objects all of which contain a string in the following format:

yyyy/MM/dd HH:mm

e.g. 2007/10/03 10:12

I'm looping through the list (no problem there) and plan on comparing each date to todays date to determine the oldest item in the list.

My question is - How do I convert this string to a date and compare it to the current date?

Just to keep things interesting I am limited to using 1.4.2 of the Java SDK.

I really should devote some time to learning all about date manipulation one day. In the meantime your help is much appreciated.
 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add some extra information.

When I attempt to import java.text.DateFormat, or java.text.SimpleDateFormat (which would really help me out) Eclipse tells me that "java.text can not be resolved".

That seems odd since they are both documented in the 1.4.2 reference. I tried the import statement on a workmates machine which resulted in the same problem.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably hate it because you're not familiar with the topic. Spend a half day digging into the SimpleDateFormat class, and you'll be going.

To parse strings to dates: SimpleDateFormat
or DateFormat

Example from Kode Java.

Regards, Jan
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ichiro Takeshita:
Just to add some extra information.

When I attempt to import java.text.DateFormat, or java.text.SimpleDateFormat (which would really help me out) Eclipse tells me that "java.text can not be resolved".

That seems odd since they are both documented in the 1.4.2 reference. I tried the import statement on a workmates machine which resulted in the same problem.

Show your code. Without the code, we can't tell what's wrong.

Regards, Jan
 
Ichiro Takeshita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan,

Thanks for your prompt replies.

I would have been up and converting dates like a pro if I could just import java.text.SimpleDateFormat.

It turned out to be a problem with my BuildPath in Eclipse. By adding the system libraries to the build path I was able to import SimpleDateFormat without any troubles.

Thanks again for taking the time to help.
reply
    Bookmark Topic Watch Topic
  • New Topic