File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Locale class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Locale class" Watch "Locale class" New topic
Author

Locale class

sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 21
Hi frndz,





OUTPUT:

en_US
1
0
113




OUTPUT :

en_US
1
1
2013

Here, my question is
why we have to add +1 to getMonth() and +1900 to getYear() to retrieve current System date info ..?


thanks in advacne

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Because it says so in the Javadocs of java.util.Date. For getMonth:
The value returned is between 0 and 11, with the value 0 representing January.

For getYear:
Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

But those two methods are deprecated. You should use java.util.Calendar (or JodaTime) if you want to get the current day, month and/or year.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 21
Rob Spoor wrote:Because it says so in the Javadocs of java.util.Date. For getMonth:
The value returned is between 0 and 11, with the value 0 representing January.

For getYear:
Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

But those two methods are deprecated. You should use java.util.Calendar (or JodaTime) if you want to get the current day, month and/or year.



Thanks Rob Spoor.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

You're welcome.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Locale class
 
Similar Threads
Different behaviour in internationalization
Parsing date using SimpleDateFormat for hh mm ss
a problem with Date class
Resource Bundle Error
is it possible to change jvm locale by using command line parameters ?