File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Date

 
kate damond
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic