aspose file tools*
The moose likes Java in General and the fly likes Tommorows date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tommorows date" Watch "Tommorows date" New topic
Author

Tommorows date

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi ,

I know that this is simple for most of the folks..but i cant get it right...

Well I want to get the next days date (i.e, tommorows date)

And the format i want is "yyyy-MM-dd"

How can i get at the solution..I tried it with Calendar ,gregorian...

but somehow didnt materialise..

Thnks in advance,
A kumar
Neel Chow
Ranch Hand

Joined: Jan 10, 2005
Posts: 55
Using Calendar:
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH)+1;
int year= cal.get(Calendar.YEAR);
int date = cal.get(Calendar.DATE)+1;
System.out.println(year+"-"+month+"-"+date);

Hope this helps...
Neel Chow
Ranch Hand

Joined: Jan 10, 2005
Posts: 55
month start with 0 in Calendar.So month+1;
to get tomorrows date date+1;
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks ....I will try this out.....
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Can we do this using GregorianCalendar..?
Neel Chow
Ranch Hand

Joined: Jan 10, 2005
Posts: 55
GregorianCalendar is a concrete subclass of Calendar.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
There is a problem with the code.Suppose my system date is 31 march...

then the output is 2005-03-32 which is wrong i believe...

Thanks..
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by A Kumar:
There is a problem with the code.Suppose my system date is 31 march...

then the output is 2005-03-32 which is wrong i believe...

Thanks..


You can't just add 1 to the value returned as the date. You will get what you described. Try this...



James Carman, President<br />Carman Consulting, Inc.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

for formatting date you can simply use this


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Neel Chow
Ranch Hand

Joined: Jan 10, 2005
Posts: 55
You are right..you just cannot add 1 to a date..
just slipped over my head...
sorry for that...
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Appreciate all ur help
Thanks vryone....

I had eventually this piece of code..

Calendar now = Calendar.getInstance( );
SimpleDateFormat formatter= new SimpleDateFormat ("yyyy-MM-dd");
System.out.println("It is now " +formatter.format(now.getTime( )));
now.add(Calendar.DATE,1);
System.out.println("Tom is " +formatter.format(now.getTime( )));


Thanx
A Kumar.
pradeep jaladi
Ranch Hand

Joined: Nov 21, 2004
Posts: 65
hi,
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, + 1);
S.O.P(calendar);
//add one day more


Pradeep.Jaladi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tommorows date