- 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
How to format and display date in Java as '201904'
To format and display date like this i.e. YearMonth, you need to set the pattern:
uuuuMM
At first, set a LocalDate:
LocalDate localDate = LocalDate.now();
Now format and display date as ‘201904’:
localDate.format(DateTimeFormatter.ofPattern("uuuuMM"))
Example
import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Demo { public static void main(String[] args) { LocalDate localDate = LocalDate.now(); System.out.println("Date = "+localDate); System.out.println("Date (Year and Month) = "+localDate.format(DateTimeFormatter.ofPattern("uuuuMM"))); } }
Output
Date = 2019-04-19 Date (Year and Month) = 201904
Advertisements