This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calendar function to set date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar function to set date" Watch "Calendar function to set date" New topic
Author

Calendar function to set date

sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
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

Joined: Sep 08, 2007
Posts: 3064
    
  33

This might be useful: JavaDatesFaq


Mohamed Sanaulla | My Blog
Pawan Kr Gupta
Greenhorn

Joined: Nov 21, 2010
Posts: 26
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

Please UseCodeTags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
wood burning stoves
 
subject: Calendar function to set date
 
Similar Threads
How to get current date and time
A challenge while formatting date value from the database
DateFormat.format unexpected side effect
Need to get a Day from Date
List Vs Set