Afficher la date et l’heure courante en Java

Dans ce tutoriel nous allons découvrir les différent façons pour afficher la date et l’heure du système courante en Java.
 
 

Méthode 1: SimpleDateFormat
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
	public static void main(String[] args) {
	  SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
	  Date date = new Date();
	  System.out.println(s.format(date));
	}
}

 
Sortie:

10/03/2020 23:31:23

 

Méthode 2: LocalDate
public class Main {
	public static void main(String[] args) {
	  System.out.println(java.time.LocalDate.now());
	}
}

 
Sortie:

2020-03-10

 

Méthode 3: LocalTime
public class Main {
	public static void main(String[] args) {
	  System.out.println(java.time.LocalTime.now());
	}
}

 
Sortie:

23:34:56.477

 

Une réflexion sur “Afficher la date et l’heure courante en Java

  • octobre 12, 2022 à 8:19 am
    Permalien

    un très bon site et bon travail ،continuez

    Répondre

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *