Solved

Displaying the year for a Date object...

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Requested array size exceeds VM limit 3 84
eclipse java  build path 6 45
object oriented programming comparison 5 56
arguments to jar 5 15
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

895 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

11 Experts available now in Live!

Get 1:1 Help Now