CodesJava

Easy learning with example program codes

Date to string in java


Java convert date to string java example

package com.codesjava;
 
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.

Please follow and like us:
Posted in Java   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki