Solved

Displaying the year for a Date object...

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

758 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

21 Experts available now in Live!

Get 1:1 Help Now