Java – Formatting Date to different Formats

 

package com.pwn.dateUtil;

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

public class dateFormat {

	public static void main(String[] args) {
		Date today = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"dd-MMM-yy");
		System.out.println(dateFormat.format(today));
		dateFormat.applyPattern("dd-MM-yyyy");
		System.out.println(dateFormat.format(today));
		dateFormat.applyPattern("dd-MM-yyyy HH:mm:ss E");
		System.out.println(dateFormat.format(today));

	}

}
29-Jan-18
29-01-2018
29-01-2018 16:53:11 Mon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s