File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String to Date - JDK 1.4.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String to Date - JDK 1.4.2" Watch "String to Date - JDK 1.4.2" New topic
Author

String to Date - JDK 1.4.2

Ichiro Takeshita
Greenhorn

Joined: May 29, 2007
Posts: 9
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

Joined: May 29, 2007
Posts: 9
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

Joined: Dec 20, 2006
Posts: 2516
    
  10

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


OCUP UML fundamental and ITIL foundation
youtube channel
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

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

Joined: May 29, 2007
Posts: 9
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String to Date - JDK 1.4.2