Java - Write code to format Date To String in yyyy-MM-dd format

Requirements

Write code to format Date To String in yyyy-MM-dd format

Demo

//package com.book2s;

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));
    }//  w w  w . ja  va 2  s .c  o  m

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