Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

first day of next year

  Asked By: Harley    Date: Sep 24    Category: Java    Views: 2683
  

How do you get the first day of the next year eg. 01/01 if your
method passes in a Date object.

ie. public Date nextFirstOfYear(Date d) {
//convert the date
//return the Date
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Midissia Lopez     Answered On: Sep 24

you'll need to create a Calendar object, modify, and then return...

public Date nextFirstOfYear(Date d) {
// assume parameter d = 4/15/2002 10:15:00 AM

// new calendar (today) 5/30/2002 12:00:00 PM
Calendar cal = Calendar.getInstance();

// reset calendar to parameter's value
cal.setTime(d);
// set month to january
cal.set(Calendar.MONTH, Calendar.JANUARY);
// set day  to the 1st
cal.set(Calendar.DATE, 1)
// set year  to (this year + 1)
cal.add(Calendar.YEAR, 1);

// return 1/1/2003 10:15:00
return cal.getTime();
}

 
Didn't find what you were looking for? Find more on first day of next year Or get search suggestion and latest updates.




Tagged: