aspose file tools*
The moose likes Java in General and the fly likes GregorianCalendar to string and back to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "GregorianCalendar to string and back to Date " Watch "GregorianCalendar to string and back to Date " New topic
Author

GregorianCalendar to string and back to Date

mangesh lele
Greenhorn

Joined: Jan 17, 2003
Posts: 18
hi
I want to carry out validation on a GregorianCalendar instance to check if it is present in my database as a corresponding Oracle Date field
In the existing framework, the validation is done by a class which takes String argument and parses it to get a Date object (using DateFormat).
The class which calls the validation class gets the GregorianCalendar instance which is to be validated.
How can I pass a String representation of this GregorianCalendar instance to the validation class so that it can convert it back to an SQL Date object?
Sample Code:
The Validation class: -
.
.
.
.
.
public boolean checkAll(String iDate){
.
.
.
.
SimpleDateFormat sdfInput=new SimpleDateFormat("MM-dd-yyyy");

Date mDateValue = sdfInput.parse(iDate);
PreparedStatement lPreStatement.setDate(1,(java.sql.Date)mDateValue);
.
.
.
.
}

The Calling class: -
.
.
.
.
.
.
String lSomeDate; //to be populated with GregorianCalendar representation
boolean lbIsDatePresent = checkAll(lSomeDate);
.
.
.
.
Hope I havent made it too cryptic
Thanks in advance.
[ May 26, 2003: Message edited by: mangesh lele ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Use the Calendar's .getTime() method, which returns a java.util.Date representation of the Calendar.
I would even overload the checkAll method to accept a Date, so that you don't have to convert the Date to a String and then back to a Date.
[ May 26, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
mangesh lele
Greenhorn

Joined: Jan 17, 2003
Posts: 18
thanks joel
i know my requirement is a pretty roundabout way of doing things and could be made lot easier, but the thing is since i'm plugging validations into an existing framework, i have to stay within its constraints.
so my real problem is that the only message that can be passed from calling class to validation class is a String object, and hence needs to be converted back and forth.
 
Consider Paul's rocket mass heater.
 
subject: GregorianCalendar to string and back to Date