... Ce que je veux faire donc c'est récupérer une Chaine contenant une date, la convertir au format Date pour pouvoir ensuite faire des comparaisons avec la date du jour (date1.before(date2) etc...) ...
La classe Locale représente une région culturelle, politique ou géographique. Une opération qui requiert un objet Locale pour exécuter sa tâche est appelé locale-sensitive et l'utilise pour adapter l'information pour l'utilisateur. Par exemple, l'affichage d'un nombre est une opération locale-sensitive puisqu'il devrait être formaté selon l'environnement géographique et culturel de l'utilisateur.
public static void main(String[] args) { // Make a new Date object. It will be initialized to the // current time. Date now = new Date();
// Print the result of toString() String dateString = now.toString(); System.out.println(" 1. " + dateString);
// Make a SimpleDateFormat for toString()'s output. This // has short (text) date, a space, short (text) month, a space, // 2-digit date, a space, hour (0-23), minute, second, a space, // short timezone, a final space, and a long year. SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.US);
// See if we can parse the output of Date.toString() try { Date parsed = format.parse(dateString); System.out.println(" 2. " + parsed.toString()); } catch(ParseException pe) { System.out.println("ERROR: Cannot parse \"" + dateString + "\""); }
// Print the result of formatting the now Date to see if the result // is the same as the output of toString() System.out.println(" 3. " + format.format(now)); } }