How to get a Date without time in Java

2 Answers

0 votes
import java.time.LocalDate;

public class MyClass {

    public static void main(String args[]) {
        System.out.println(LocalDate.now());
    }
}
  
  
  
  
/*
run:
   
2023-11-19
   
*/

 



answered Nov 19, 2023 by avibootz
0 votes
import java.util.Date;
import java.text.SimpleDateFormat;  

public class MyClass {

    public static void main(String args[]) {
        Date currentDate = new Date();
        
        SimpleDateFormat dateFormat= new SimpleDateFormat("dd/MM/yyyy");
        
        String dateOnly = dateFormat.format(currentDate);

        System.out.println(dateOnly);
    }
}
  
  
  
  
/*
run:
   
19/11/2023
   
*/

 



answered Nov 19, 2023 by avibootz
...