File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to Date - JDK 1.4.2

 
Ichiro Takeshita
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jan Cumps
Bartender
Posts: 2575
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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: 2575
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic