This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Making String to java.util.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Making String to java.util.Date" Watch "Making String to java.util.Date" New topic

Making String to java.util.Date

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 833
I am getting date from HTML form i.e.

String days=req.getParameter("days");
String months=req.getParameter("months");
String year=req.getParameter("year");

String job_start=days+"-"+months+"-"+year;
String job_end=days1+"-"+months1+"-"+year1;

How can I convert and compare with todays date?

My Code:

What I did is; certainly its wrong aproach as:

1. I am trying to write String instead of java.util.Date
2. I am getting today date with oracle and don't know as to how can in get from Java

Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 423

java.util.Date has many deprecated methods, so I advise you to use java.util.GregorianCalendar.

Take a look in the following link to understand the compare() method:

Also notice that if you have the dates represented in String, you can compare them using the equals() method.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20183

Or check out DateFormat and its most-often used subclass SimpleDateFormat.

How To Ask Questions How To Answer Questions
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 833
Thanks from the bottom of my heart
I agree. Here's the link:
subject: Making String to java.util.Date
It's not a secret anymore!