Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Problem with Calendar class
Bharadwaj Adepu
Ranch Hand
Posts: 99
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is the piece of code am trying to execute
Calendar cal = Calendar.getInstance(); cal.set(2008, 10, 29); int weekday = cal.get(Calendar.DAY_OF_WEEK); int month = cal.get(Calendar.MONTH); System.out.println(cal.getTime().toString()); System.out.println("Weekday: " + weekday); System.out.println("Month: " + month);
Iam setting todays date and tring to get the DAY_OF_WEEK, its showing the next months day of same date, why so?
please explain!
This is the output
2008 10 29 Sat Nov 29 21:08:39 IST 2008 Weekday: 7 Month: 10
SCJP 1.5
Joanne Neal
Rancher
Posts: 3742
16
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try using
cal.set(2008, Calendar.OCTOBER, 29);
instead. Calendar indexes the months from 0 to 11, so 10 is actually November.
Joanne
Campbell Ritchie
Marshal
Posts: 79177
377
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Go through the
Calendar class API documentation
and you find October isn't 10! Use Calendar.OCTOBER instead.
If you go through the documentation you find a link to "constant field values" and there you find out what the values are.
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Date not working
Tommorows date
getting a Date that is 30 days ago from today
Problem with adding months to Gregorian Calender
Retrieve value from a DateField
More...