Date to string in java

Java convert date to string java example

package com.w3spoint;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class DateToString {
  public static void main(String args[]){
	try {
		DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
		String dateString = df.format(new Date());
		System.out.println("Date: " + dateString);
	} catch (Exception e) {
		e.printStackTrace();
	}
  }
}

Output:

Date: 18-Mar-2018

Download this example.

Content Protection by DMCA.com
Please Share