This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java API - to get next year Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java API - to get next year" Watch "Java API - to get next year" New topic

Java API - to get next year

Shadab F Hashmi

Joined: Feb 13, 2006
Posts: 9

I have a requirement where i have a date like "2006-08-21 09:53:58.0", so i need to get the last date of the next year like "2007-12-31 09:53:58.0".

Does Java API provide any method where if i give the date like "2006-08-21 09:53:58.0" and output i get "2007-12-31 09:53:58.0".

Can anyone please mail me the code.

Thanks inadvance for all the help.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

Check out the java.util.Calendar class.
[ September 12, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Denysis Volpi

Joined: Sep 13, 2006
Posts: 1
I think I would use a GregorianCalendar to construct a date:

GregorianCalendar(int year, int month, int date, int hour, int minute, int second) Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

Then use the set() function of the Calendar class

set(int year, int month, int date)
Sets the values for the fields year, month, and date.

To set the new year, month and day values.
I agree. Here's the link:
subject: Java API - to get next year
It's not a secret anymore!