IntelliJ Java IDE
The moose likes Java in General and the fly likes Getting first date of next month Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Getting first date of next month" Watch "Getting first date of next month" New topic
Author

Getting first date of next month

Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 147
Hi,

Does anyone know how we can get the first date of next month? So for example if I have a Date object for "Feb 7, 2012" I need to get "March 1, 2012".

Thanks in advance for any help.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Class java.util.Calendar has methods to do this. I'd do it like this: get a Calendar instance, set the day of the month to 1, then add 1 month. Lookup the API documentation of class Calendar for the appropriate methods to use.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18375

Check out java.util.Calendar.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
 
subject: Getting first date of next month
 
Threads others viewed
first date and last date of month
getting first and last date of past 6 months?
the date of the last day of month
Using the "this" keyword
Calendar class methods give weird results