- 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 today’s date in Java with SimpleDateFormat
To work with SimpleDateFormat class in Java, import the following package.
import java.text.SimpleDateFormat;
To get the date, use the format() method as shown below. Firstly, set the date format −
Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy");
Now, we will get the date −
simpleformat.format(cal.getTime())
The following is the complete example −
Example
import java.text.SimpleDateFormat; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); } }
Output
Today's date = 26/11/2018
- Related Articles
- Display seconds with SimpleDateFormat(“s”) in Java
- Set Date patterns with SimpleDateFormat in Java
- Display hour with SimpleDateFormat(“H”) in Java
- Display minutes with SimpleDateFormat(“m”) in Java
- Display hour with SimpleDateFormat(“hh”) in Java
- Java Program to format date with SimpleDateFormat
- Display time zone with SimpleDateFormat(“z”) in Java
- Display record with today and tomorrow’s date from a column with date record in MySQL
- Display minutes with SimpleDateFormat('mm') in Java
- Display seconds with SimpleDateFormat('ss') in Java
- Display year with SimpleDateFormat('yyyy') in Java
- Display the month number with SimpleDateFormat(“M”) in Java
- Display AM/PM time marker with SimpleDateFormat(“a”) in Java
- Display day number with SimpleDateFormat('d') in Java
- How to subtract date from today's date in JavaScript?

Advertisements