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

 Live Demo

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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

152 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements