• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Making String to java.util.Date

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

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: http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#compareTo%28java.util.Calendar%29

Also notice that if you have the dates represented in String, you can compare them using the equals() method.
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or check out DateFormat and its most-often used subclass SimpleDateFormat.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks from the bottom of my heart
 
He's giving us the slip! Quick! Grab this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic