How to Display the Last Two Digits of the Current Year in Java

1 min read
Date: 2025-03-05
This Java tutorial demonstrates three methods to extract the last two digits of the current year. It uses the Calendar
class (legacy), SimpleDateFormat
(for formatting), and the java.time
package (modern Java 8+). Each method involves obtaining the full year and then using the modulo operator (%) with 100 to get the last two digits. The java.time
approach using Year.now().getValue() % 100
or LocalDate.now().getYear() % 100
is recommended for modern applications due to its improved design.
0
Subscribe to my newsletter
Read articles from Yatin batra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
