How to convert date format in java?

3.76K viewsJava
0

how to convert date format in java ,i want to convert the date format.

Example : dd-mm-yyyy to dd/mm/yyyy

Manohar Changed status to publish June 16, 2019
Add a Comment
0

U can use the below method for changing the date format :

public static String formatDate(String dateString, String fromDate, String toDate) {
		DateFormat readFormat = new SimpleDateFormat(fromDate);
		DateFormat writeFormat = new SimpleDateFormat(toDate);
		Date date = null;
		try {
			date = readFormat.parse(dateString);
		} catch (ParseException e) {
			// here write the logs for identifying the runntime errors
		}
		String formattedDate = "";
		if (date != null) {
			formattedDate = writeFormat.format(date);
		}
		return formattedDate;
	}

 

Manohar Changed status to publish June 17, 2019
Add a Comment
Write your answer.