- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display four-digit year in Java
Use the ‘Y’ date conversion character to display four-digit year.
System.out.printf("Four-digit Year = %TY
",d);
Above, d is a date object −
Date d = new Date();
The following is an example −
Example
import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) throws Exception { Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a"); String format = dateFormat.format(d); System.out.println("Current date and time = " + format); System.out.printf("Four-digit Year = %TY
",d); } }
Output
Current date and time = 26/11/2018 11:56:26 AM Four-digit Year = 2018
- Related Articles
- Display two-digit year in Java
- Display three-digit day of the year in Java
- Display first two digits of year in Java (two-digit century)
- Display two-digit month in Java
- Generate 10 random four-digit numbers in Java
- Display Month of Year using Java Calendar
- Display year with SimpleDateFormat('yyyy') in Java
- Display two-digit day of the month in Java
- Java Program to display previous year from GregorianCalendar
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to Display Name of the Weekdays in Calendar Year
- Java Program to Enter a Number in Digit and Display in Words
- Java Program to Display Name of Months of Calendar Year in Short Format
- Multiple Digit Decimal Display (4 Digits)
- Conversion of four-digit hex to ASCII in 8051

Advertisements