Skyaz123 / imagesnw

0 stars 0 forks source link

Date in Java #7

Open Skyaz123 opened 2 weeks ago

Skyaz123 commented 2 weeks ago
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class CurrentDateExample {
    public static void main(String[] args) {
        // Get the current date
        LocalDate currentDate = LocalDate.now();

        // Define the date format
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");

        // Format the date and store it in a variable
        String formattedDate = currentDate.format(formatter);

        // Print the formatted date
        System.out.println("Current date in DD-MM-YYYY format: " + formattedDate);
    }
}