CodesJava

Easy learning with example program codes

String to date in java


Java convert string to date java example

package com.codesjava;
 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class StringToDate {
  public static void main(String args[]){
	  try {
		String dateString = "18-Mar-2018";
		  DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
		  Date date = df.parse(dateString);
		  System.out.println("Date: " + date);
	} catch (ParseException e) {
		e.printStackTrace();
	}
  }
}

Output:

Date: Sun Mar 18 00:00:00 IST 2018

Download this example.

Please follow and like us:
Posted in Java   


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