java - calendar api to set many dates -


    import java.util.calendar;     import java.util.date;     public class employee {         private calendar doj;          public employee(calendar date) {             // todo auto-generated constructor stub             this.doj=date;         }         public date getdoj()          {              date cal=calendar.getinstance().gettime();             return cal;          }       }  import java.text.simpledateformat; import java.util.arraylist; import java.util.calendar; import java.util.list;   public class testemployeesort {      /**      * @param args      */     public static void main(string[] args) {         // todo auto-generated method stub         list<employee> coll = getemployees();         printlist(coll);     }         public static list<employee> getemployees()          {              list<employee> col = new arraylist<employee>();             //simpledateformat format=new simpledateformat("dd/mm/yyy");             col.add(new employee(null));             return col;         }          private static void printlist(list<employee> list) {              system.out.println("date of joining");               (int = 0; < list.size(); i++) {                  employee e = list.get(i);                  system.out.println(e.getdoj());              }          }      } 

this prints current date. want set date following have used date. want same using calendar api

public static list<employee> getemployees()         {              list<employee> col = new arraylist<employee>();              col.add(new employee(5, "xyz","abc", new date(1986, 6,12), new date(1986, 6,12)));                     return col;         } 

you can use calendar.set() method set calendar object specific year, month, day.

public static list<employee> getemployees() {      list<employee> col = new arraylist<employee>();     calenader cal1 = calendar.getinstance();     cal1.set(1986, 6, 12);     calenader cal2 = calendar.getinstance();     cal2.set(1986, 6, 12);     col.add(new employee(5, "xyz","abc", cal1, cal2));     return col; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -