Results 1 to 6 of 6
  1. #1
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default getYear deprecated method

    I want to get the current year and tried the following.

    Java Code:
    System.out.println(date.getYear());
    I came to know that getYear() is deprecated and further more it returns 108 which does not makes sense. Please tell me a better way of doing this.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Java Code:
    System.out.println(Calendar.getInstance().get(Calendar.YEAR));
    ...
    Please refer to the Date Java doc, how they have justified the depreciation.
    dont worry newbie, we got you covered.

  3. #3
    Vering is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by ravian View Post
    I want to get the current year and tried the following.

    Java Code:
    System.out.println(date.getYear());
    I came to know that getYear() is deprecated and further more it returns 108 which does not makes sense. Please tell me a better way of doing this.
    If you look in the doc for getYear() it 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.

    2008-1900 = 108

    Don't ask me who ever got this idea...
    Last edited by Vering; 01-05-2011 at 08:02 AM.

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by roots View Post
    Please refer to the Date Java doc, how they have justified the depreciation.
    Here are links to javadoc:-

    Calendar and Date

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    This thread is almost 2yrs old.

  6. #6
    Vering is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by mine0926 View Post
    This thread is almost 2yrs old.
    I know. It might not help the originator much, but I found this thread myself today, and so may others in the future.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 01:23 PM
  3. I need help with a deprecated program
    By mikau in forum New To Java
    Replies: 0
    Last Post: 02-13-2008, 09:34 AM
  4. Using Deprecated Methods
    By ravian in forum New To Java
    Replies: 3
    Last Post: 11-23-2007, 07:58 PM
  5. method size is deprecated
    By oregon in forum New To Java
    Replies: 4
    Last Post: 08-05-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •