Solved

Displaying the year for a Date object...

Posted on 1998-02-09
3
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
gwalters earned 50 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

624 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