Convert Date To String in MM-dd-yyyy format - Java java.util

Java examples for java.util:Date Format

Description

Convert Date To String in MM-dd-yyyy format

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) {
        Date date = new Date();
        System.out.println(DateToString(date));
    }/*from  www  . ja va 2s  .  c  om*/

    public static String DateToString(Date date) {
        SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy");
        return df.format(date);
    }
}

Related Tutorials