Link to home
Start Free TrialLog in
Avatar of prograMNewbie
prograMNewbie

asked on

Convert a string("dd-mm-yy") to type date and the reverse of .add method


Is it possible to convert a string in this format : "dd-mm-yy" to type date so .add operation can be perfomed on it. As in:

String date = rs112.getString("expdate");
Calendar finishDate = Calendar.getInstance(date);
finishDate.add(Calendar.DAY_OF_YEAR, roll_amt);

Is there a reverse method of .add so that a date can be rolled back a certain number of days?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use SimpleDateFormat


SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
finishDate.setTime(sdf.parsedate));
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
String date = rs112.getString("expdate");
Calendar finishDate = Calendar.getInstance();
finishDate.setTime(sdf.parse(date));
finishDate.add(Calendar.DAY_OF_YEAR, roll_amt);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prograMNewbie
prograMNewbie

ASKER

Sorry about the delay, CEHZ: Your code worked perfect, thanks

Thanks objects for ur comments
,8-)
Glad I could help :)