Format a date in java using DateFormat - Java @ Desk

Thursday, May 16, 2013

Format a date in java using DateFormat




Click Get Current Date and Time across TimeZone in Java




import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FormatDate {
    public static void main(String args[]) {

        String format = "dd-MM-yyyy";
        DateFormat dateFormat = new SimpleDateFormat(format);
        Date currentDate = new Date();
        System.out.println("Current date in " + format + " format : " + formatDate(dateFormat, currentDate));
    }

    public static String formatDate(DateFormat dateFormat, Date date) {
        return dateFormat.format(date);
    }
}






No comments:

Post a Comment