Results 1 to 4 of 4
Thread: Gregorian Calendar
- 01-25-2013, 10:09 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
Gregorian Calendar
Hi All!
I am having difficulties with GregorianCalendar class, working with a java book that asks to implement program that prints these results:
1) the date and weekday that is hundred days from today
2) the weekday of my birthday
3) the date that is 10,000 days from my bday.
So far, I have this:
on console windows it gives me:Java Code:import java.util.GregorianCalendar; public class Calendar { private static int DAY_OF_MONTH; private static int MONTH; private static int YEAR; private static int DAY_OF_WEEK; private static int JUNE; /** * @param args */ public static void main(String[] args) { GregorianCalendar cal = new GregorianCalendar(); //today's date GregorianCalendar mybday = new GregorianCalendar(1987, Calendar.JUNE, 9); //my birthday // now cal is a hundred days from today cal.add(Calendar.DAY_OF_MONTH, 100); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); int month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); int weekday = cal.get(Calendar.DAY_OF_WEEK); //1 is Sunday, 2 is Monday, ..., 7 is Saturday //The date and weekday that is 100 days from today System.out.println("The date and weekday that is 100 days from today"); System.out.println("MONTH: " + month); System.out.println("YEAR: " + year); System.out.println("DAY OF MONTH: "+ dayOfMonth); System.out.println("DAY OF WEEK: "+ weekday); //My birthday's weekday int dayOfMonth2 = mybday.get(Calendar.DAY_OF_MONTH); int month2 = mybday.get(Calendar.MONTH); int year2 = mybday.get(Calendar.YEAR); int weekday2 = mybday.get(DAY_OF_WEEK); System.out.println("MY BIRTHDAY'S WEEKDAY IS " + weekday2); //The date that is 10,000 days from my birthday System.out.println("The date that is 10,000 days from my birthday"); mybday.add(Calendar.DAY_OF_MONTH, 10000); System.out.println("MONTH: " + month2); System.out.println("YEAR: " + year2); System.out.println("DAY OF MONTH: "+ dayOfMonth2); System.out.println("DAY OF WEEK: "+ weekday2); } }
The date and weekday that is 100 days from today
MONTH: 1
YEAR: 1
DAY OF MONTH: 1
DAY OF WEEK: 1
MY BIRTHDAY'S WEEKDAY IS 1
The date that is 10,000 days from my birthday
MONTH: 1
YEAR: 1
DAY OF MONTH: 1
DAY OF WEEK: 1
which is of course not correct...any ideas why it is giving me wrong results? thanks!
-
Re: Gregorian Calendar
Big suggestion: don't give the class you've created the same name as a core Java class, and then give it constants (that are all 0 by default) that shadow the true Calendar class's constants and do nothing but confuse your program. Rename your program and import the true Calendar class and use *its* useful constants.
- 01-26-2013, 03:21 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 40
- Rep Power
- 0
Re: Gregorian Calendar
oh shoot! that works! thank you for your suggestions! :)
-
Similar Threads
-
Sorting Gregorian Calendar?
By JohnDas in forum New To JavaReplies: 10Last Post: 01-25-2011, 01:24 PM -
help with Gregorian Calendar
By fezman1337 in forum JCreatorReplies: 3Last Post: 10-26-2010, 04:01 AM -
Gregorian Calendar
By bindhuuk4 in forum New To JavaReplies: 1Last Post: 08-07-2009, 12:00 PM -
Help with gregorian calendar
By osval in forum New To JavaReplies: 2Last Post: 08-06-2007, 11:21 PM -
Gregorian calendar issue
By orchid in forum New To JavaReplies: 1Last Post: 05-16-2007, 06:51 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks