how to get SimpleDateFormat to give me numbers like 13/6/2021?



is there a way to let the simple date format to give me numbers not names its giving me 12 jul, 2021

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
``

Answer

Are you looking for :

import java.time.LocalDateTime;  // Import the LocalDateTime class
import java.time.format.DateTimeFormatter;  // Import the DateTimeFormatter class

public class Main {
  public static void main(String[] args) {  
    LocalDateTime myDateObj = LocalDateTime.now();  
    System.out.println("Before Formatting: " + myDateObj);  
    DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd/MM/yyyy");  
    
    String formattedDate = myDateObj.format(myFormatObj);  
    System.out.println("After Formatting: " + formattedDate);  
  }  
}  

// Output:

/*
Before Formatting: 2021-06-13T19:28:32.056915

After Formatting: 13/06/2021
*/


Source: stackoverflow