0 votes
in Java by
How to convert date to date format in java? In java how to format date to date format?

1 Answer

0 votes
For formatting date to use SimpleDateFormat class of java. And give our format in constructor. For more you can see the following example:
package com;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateToDateFormat {
* @param args
public static void main(String[] args) {
DateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
Calendar cal = Calendar.getInstance();
Date currDate = cal.getTime();
String strDate = sdf.format(currDate);
System.out.println("Current Date: " + currDate + ", Formated Date: " + strDate);
Current Date: Mon Sep 23 16:52:48 IST 2013, Formated Date: 09-23-2013 16:52:48

Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.