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));
    }//from   ww  w .  jav  a2  s  .c  om

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