File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.Date" Watch "java.util.Date" New topic


kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
I have a text field, and my users will be typing a date in the format "dd-MM-yyyy" and I can check this. How can I construct a java.util.Date from this ? Will I have to extract each integer and calculate the appropriate number in milliseconds ?
Has anyone done this ? I'm a bit wary of the whole Date thing cos all the useful easy methods seem to be deprecated !
(actually, I'm feeling a bit depreKated at the moment too)
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Kate, I think this example should help.
import java.text.*;
import java.util.Date;
public class DateTest
public static void main(String[] args)
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date d = sdf.parse("02-05-1999");
catch (ParseException e)
I agree. Here's the link:
subject: java.util.Date
It's not a secret anymore!