0

how could I get today's date (current system date) on format yyyy-mm-dd (just date and not dateTime) to compare with some other dates of the same format.

Saad
  • 21
  • 1
  • 2
  • 4

3 Answers3

5

You can use a SimpleDateFormat to format a new Date():

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String formatted = df.format(new Date());
Ben Watson
  • 4,984
  • 4
  • 36
  • 62
Mureinik
  • 277,661
  • 50
  • 283
  • 320
1

Try this:-

  public static void main(String[] args) {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
            String formatted = format1.format(cal.getTime());
            System.out.println(formatted);
        }
Goyal Vicky
  • 1,141
  • 13
  • 15
0

Try creating a variable in this format.

LocalDateTime date = LocalDateTime.now();
System.out.println( date );
DalekCaan99
  • 51
  • 1
  • 8