How to Format Date and Time Using SimpleDateFormat Class in Java


Here we may learn how to define and use SimpleDateFormat Class to format date and time in Java.

Source Code

package com.beginner.examples;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatExample {

	public static void main(String[] args) {
		
		// Create Date.
		Date date = new Date();
		
		//Use "MM/dd/yyyy" date format.
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");
		
		System.out.println("Today is " + simpleDateFormat.format(date) );

	}

}

Output:

Today is 06/13/2019

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments