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.
            Asked
            
        
        
            Active
            
        
            Viewed 2.4k times
        
    3 Answers
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
- 
                    thanks for the help. but what if want to have this date in a java date object? – Saad Aug 17 '15 at 20:05
0
            
            
        Try creating a variable in this format.
LocalDateTime date = LocalDateTime.now();
System.out.println( date );
 
    
    
        DalekCaan99
        
- 51
- 1
- 8
