Convertir String "j.m.a" en date de mm forma

tunisiano22 -  
choubaka Messages postés 5535 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

SVp est ce qu'il ya qq qui peut me dire comment je peux convertire un String en une date, en java, tout en gardant la même forma: "jours.mois.année" sans heure ni autre information.

Merci d'avance.

1 réponse

  1. choubaka Messages postés 5535 Date d'inscription   Statut Modérateur Dernière intervention   2 113
     
    salut

    deux méthodes possibles

    parse
    
    public Date parse(String source)
               throws ParseException
    
        Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
    
        See the parse(String, ParsePosition) method for more information on date parsing.
    
        Parameters:
            source - A String whose beginning should be parsed. 
        Returns:
            A Date parsed from the string. 
        Throws:
            ParseException - if the beginning of the specified string cannot be parsed.
    
    parse
    
    public abstract Date parse(String source,
                               ParsePosition pos)
    
        Parse a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039928046).
    
        By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
    
        Parameters:
            source - The date/time string to be parsed
            pos - On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed. 
        Returns:
            A Date, or null if the input could not be parsed
        See Also:
            setLenient(boolean)
    
    
    0