Solved

Displaying the year for a Date object...

Posted on 1998-02-09
3
172 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now