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
Calendar shows incorrect date
nandish chitalia
Greenhorn
Posts: 7
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have a simple code here
Calendar currentDate = Calendar.getInstance();
System.out.println("currentDate : " + currentDate.get(Calendar.DAY_OF_MONTH) + "/" + currentDate.get(Calendar.MONTH) + "/" + currentDate.get(Calendar.YEAR));
I executed this on the 7th of September 2007...i.e. 07/09/2007.
The output is
currentDate : 7/8/2007
Am I missing something fundamental here? Please help and thanks in advance.
bart zagers
Ranch Hand
Posts: 234
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is one of the nice things about Calendar.
As documented in the api javadoc, months start at zero
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Use a formatter such as SimpleDateFormat to format dates:
Calendar cal = Calendar.getInstance(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); System.out.println("currentDate : " + df.format(cal.getTime()));
Jesper's Blog
-
Pluralsight Author Page
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
time
Date validation
getting system date
Why they have named a calendar method like this?
setTime() function not setting the time
More...