Beginner
Beginner

Reputation: 875

Calendar in Java

I have to add the no of delays to calendar type , and wants the new date in Calendar Type only.

limitDate = orderDate + settlementDelay.

where

limitDate = java.util.Calendar

orderDate = java.util.Calendar

settlementDelay = int 

I tried something like this :

Calendar limitDate = order.getOrderDate().add(Calendar.DATE,settlementDelay);

But its giving me the

Type mismatch error: Cannot convert from void to Calendar.

Can anybody help me out?

Upvotes: 0

Views: 2849

Answers (2)

David Pierre
David Pierre

Reputation: 9535

You should consider using the joda-time library instead.

It's far better for date manipulations. It does has the plusDays method you seem to want.

DateTime orderDate = ...;
DateTime limitDate = orderDate.plusDays(settlementDelay);

Upvotes: 0

anubhava
anubhava

Reputation: 785146

You're getting this error because Calendar#add() method doesn't return anything (see void) and adds the input date/month/year etc in the supplied Calendar instance itself.

EDIT: If you really need a new instance then use code like this:

Calendar limitDate = Calendar.getInstance();
limitDate.setTime( orderDate.getTime() );
limitDate.add(Calendar.DATE, settlementDelay);

Upvotes: 5

Related Questions