-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);
YCF_L
  • 51,266
  • 13
  • 85
  • 129
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);

}
YCF_L
  • 51,266
  • 13
  • 85
  • 129
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,543
  • 4
  • 27
  • 30