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

7

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
  • 5,357
  • 4
  • 42
  • 65
Mureinik
  • 297,002
  • 52
  • 306
  • 350
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,249
  • 16
  • 16
0

Try creating a variable in this format.

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