2010-12-02 4 views
-1
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"); 

      for (int i = 0; i < list.size(); i++) { 
       Employee e = list.get(i); 
       System.out.println(e.getDoj()); 
      } 
     } 
    } 

これは、現在の日付を出力します。しかし、私は日付を使用している次のような日付を設定したい。あなたはカレンダーを使用したいが、あなたは特定の日付に設定する必要があります。しかし、私は私が正しくあなたの問題を理解している場合わからないそれを用いたカレンダーのAPIカレンダー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; 
     } 
+1

あなたの質問は本当に理解できません。 –

答えて

2

のようなものを試してみてください。

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; 
} 
+0

printList()で印刷する方法私は従業員クラスとprintList()で何をすべきですか? – Sumithra

0

をしたいですか? APIにはこのための設定方法があると言われています。

0

は、あなたが特定の年にカレンダーオブジェクトを設定するCalendar.set()メソッド、月、日を使用することができます

Calendar c = Calendar.getInstance(); 
c.set(2000, 1, 10); 

System.out.println(c.getTime()); 
関連する問題