java - How to Merge Two Dates in EJB JPA -
i try merge 2 dates, current date , date in ejb of jpa it's class userbean in class prepare 1 method setexpiredate. method use merge 2 dates 1 currentdate{new date()
} , date {new date(1,6,0)
}
@stateless(mappedname = "cms/userbean") public class userbean implements userbeanlocal { @persistencecontext(name = "cms-ejbpu") entitymanager em; @override public boolean setexpiredate(int userid,int planid) { try { entitybean.user usr = em.find(entitybean.user.class, userid); int day = 20; int month = 6; int year = 0; date expr = new date() + new date(year, month, day); usr.setexpiredate(expr); return true; } catch(exception ex) { system.out.println("error occure, while setting expiredate"); return false; } }
you should consider using joda-time handle dates, better api jdk comes with.
to manipulate dates standard jdk classes, use calendar class:
calendar calendar = calendar.getinstance(); // calendar.add(calendar.month, 1); calendar.add(calendar.date, 2); calendar.add(calendar.year, 3); date result = calendar.gettime();
Comments
Post a Comment