Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying the year for a Date object...

Posted on 1998-02-09
3
Medium Priority
?
178 Views
Last Modified: 2012-05-04
I am trying to figure out how to display the year in normal format when calling Date.getYear().  For example, the year 1998 is represented as 98 when I call Date.getYear(), but how can I get 1998 instead?
0
Comment
Question by:bjg
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
gwalters earned 200 total points
ID: 1232957
Add 1900 to it.

I realize this sounds like a lame answer, but the API specifically says getYear() "Returns the year after 1900."  

I know what you want: something that will be portable.  The answer is that, if the method is implemented according to the spec (such as it is ;), adding 1900 to the answer is correct.


0
 

Author Comment

by:bjg
ID: 1232958
Thanks, I ended up using Calendar instead, since most of the Date methods are deprecated in favor of Calendar now.
0
 

Author Comment

by:bjg
ID: 1232959
Thanks, I ended up using Calendar instead, since most of the Date methods are deprecated in favor of Calendar now.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question