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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -