Here I have attached SimpleDateFormat Example in Java Programming language. Its tested and output is displayed below.

SimpleDateFormatExample.java

package com.javatraineronline.example;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SimpleDateFormatExample {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat();
System.out.println("Default Date : "+date);
// Format 1
df.applyPattern("dd/MM/yyyy");
System.out.println("Formatted Date (dd/MM/yyyy): "+df.format(date));
// Format 2
df.applyPattern("dd-MM-yyyy");
System.out.println("Formatted Date (dd-MM-yyyy): "+df.format(date));
// Format 3
df.applyPattern("dd.MM.yyyy");
System.out.println("Formatted Date (dd.MM.yyyy): "+df.format(date));
// Format 4
df.applyPattern("EEE, MMM d, yyyy");
System.out.println("Formatted Date (EEE, MMM d, yyyy): "+df.format(date));
// Format 5
df.applyPattern("d MMM, yyyy");
System.out.println("Formatted Date (d MMM, yyyy): "+df.format(date));
}
}

Output

[su_box title=”Output for SimpleDateFormatExample.java”]Default Date : Wed Oct 12 11:41:39 IST 2016
Formatted Date (dd/MM/yyyy): 12/10/2016
Formatted Date (dd-MM-yyyy): 12-10-2016
Formatted Date (dd.MM.yyyy): 12.10.2016
Formatted Date (EEE, MMM d, yyyy): Wed, Oct 12, 2016
Formatted Date (d MMM, yyyy): 12 Oct, 2016
[/su_box]

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *