Have year on 4 digits from a Date objectTag(s): Date and Time

You need to add 1900 to it to get the 4 digit year.
int year = myDate.getYear() + 1900;
The getYear() method returns the number of years elapsed after the year 1900. So for year 2000, mydate.getYear() will return 100. So 100 + 1900 = 2000.


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]