Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Harley Evans   on Sep 24 In Java Category.

  
Question Answered By: Midissia Lopez   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();
}

Share: 

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


Tagged: