This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes a problem with Date class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "a problem with Date class" Watch "a problem with Date class" New topic

a problem with Date class

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
i am executing this code

import java.util.Date;

public class Test
public static void main(String ars[])


System.out.println(new Date().getYear());



I am getting the output as 105 instead of 2005

is there any error in java ?


SCJP 1.4
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Please have a look at java docs..

This is from java docs.

public int getYear()Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.

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.

[ December 30, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Also check this code
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Read the java docs when you're having a problem with a method in the API?!
The illuminati have leaked a secret meant only for true believers!
This is a banner day for the advanced forum

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: a problem with Date class
It's not a secret anymore!