GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.Date" Watch "java.util.Date" New topic
Author

java.util.Date

kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Hi,
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)
Cheers,
Kate
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");
try
{
Date d = sdf.parse("02-05-1999");
System.out.println(d);
}
catch (ParseException e)
{
System.out.println("whoops");
}
}
}
 
GeeCON Prague 2014
 
subject: java.util.Date