- 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
Format Calendar with String.format() in Java
Firstly, consider an object with date value.
Object arrObj[] = { "Date", Calendar.getInstance() };
After that, use the String.format() method to format Calendar and display the date.
The following is an example.
Example
import java.util.Calendar; public class Demo { public static void main(String []args){ Object arrObj[] = { "Date", Calendar.getInstance() }; System.out.println("Formatting Date..."); System.out.println(String.format("%1$s = %2$tY %2$tm %2$te", arrObj)); } }
Output
Formatting Date... Date = 2018 11 17
Advertisements