

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 first two digits of year in Java (two-digit century)
Use the ‘C’ date conversion character to display two digits of year −
System.out.printf("Two-digit Year (Century Name) = %tC/%TC\n", d, 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("Localized day name = %tA/%TA\n", d, d); System.out.printf("Two-digit Year (Century Name) = %tC/%TC\n", d, d); } }
Output
Current date and time = 26/11/2018 11:51:18 AM Localized day name = Monday/MONDAY Two-digit Year (Century Name) = 20/20
- Related Questions & Answers
- Display two-digit year in Java
- Display two-digit month in Java
- Display four-digit year in Java
- Display two-digit day of the month in Java
- Display two digits day number in Java
- Display three-digit day of the year in Java
- Get the correct century from 2-digit year date value - JavaScript?
- Getting century from year in JavaScript
- Python Pandas - Format the Period object and display the Year without century
- Digit distance of two numbers - JavaScript
- Program to find century for a year in C++
- Display Month of Year using Java Calendar
- Sum of digits of year in MySQL?
- 8085 Program to convert two-digit hex to two ASCII values
- Program to convert two-digit hex to two ASCII values in 8085 Microprocessor
Advertisements