-3

I want this date format YYYY-MM-DD.

Please help me on this :

java.util.Date date= new java.util.Date();
Timestamp time = new Timestamp(date.getTime()); 
System.out.println(time);
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
user2015
  • 1
  • 4

2 Answers2

1

This should help you:

public static void main(String args[]) {

    java.util.Date date = new java.util.Date();
    String time = new SimpleDateFormat("yyyy-MM-dd").format(date);
    System.out.println(time);

}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
0

Try doing it with the help of SimpleDateFormat class or simply use Joda's LocalDate.

String dateInString= new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).format(date);
System.out.println(dateInString);

Using Joda

System.out.println(LocalDate.now().toString("yyyy-MM-dd"));
SparkOn
  • 8,806
  • 4
  • 29
  • 34