Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar function to set date

 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Employee
{
private Date doj;

public Employee (Date doj)
{
this.doj=doj;
}
public Date getDoj()
{
return doj;
}
}


class TestEmployeeSort
{
public static List<Employee> getEmployees()
{
List<Employee> col=new ArrayList<Employee>();
col.add(new Employee(new Date(1986,21,22));
}
}
In the above code i have used Date to set a date. I want to know how to use calendar function to do this. I know that i can use getInstance() and set the date. But I don't know how to implement it. Please help me to know how to set Date using Calendar function
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be useful: JavaDatesFaq
 
Pawan Kr Gupta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use like this.

class Employee
{
private Date doj;

public Employee (Date doj)
{
this.doj=doj;
}
public Date getDoj()
{
return doj;
}
}



public class TestEmployeeSort
{
public static List getEmployees()
{
List col=new ArrayList();
col.add(new Employee(Calendar.getInstance().getTime()));
}
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when you post source code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic