0
votes

Comment convertir "2019-02-10T19: 30: 00 + 00: 00" Format de date à "19h30"

Je suis un nouveau développeur Android. Je voudrais analyser cette date: 2019-02-10T19: 30h00 + 00: 00 à ce format 19:30.


0 commentaires

4 Réponses :


1
votes
SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSS”);
Date sourceDate = null;
try {
sourceDate = dateFormat.parse(sourcedatevalue);
} catch (ParseException e) {
e.printStackTrace();
}

SimpleDateFormat targetFormat = new SimpleDateFormat(“HH:mm”);
targetdatevalue= targetFormat.format(sourceDate);
You can use this template.

0 commentaires

0
votes

Si vous êtes sûr que le format de votre chaîne serait XXXX-XX-XXXAB: CD: XX + XX: XX et vous avez besoin d'AB: CD Vous pouvez le faire:

val stringToFormat = "2019-02-10T19:30:00+00:00"
val formattedString = stringToFormat.substring(11,16)


0 commentaires

0
votes

Vous pouvez utiliser SimpleDateDeDateDeDateDeDaTate de Native pour analyser de telles dates.

Par exemple: P>

String yourTime = "2019-02-10T19:30:00+00:00";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'hh:mm:ss", Locale.getDefault());
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
        calendar.setTime(sdf.parse(yourTime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    SimpleDateFormat output = new SimpleDateFormat("HH:mm", Locale.getDefault());
    System.out.println(output.format(calendar.getTime()));


1 commentaires

Vous pouvez également définir la fuseau horaire par défaut sur UTC "Timezone.setDefault (TimeZone.StTimeZone (" UTC)) "et interpréter l'heure de saisie avec TimeZone comme" "AAAA-MM-DD'T'HH: MM: SSZ" Dans ce cas Pas besoin de calendrier.SetTimezone ligne.



0
votes

Essayez ceci à Kotlin:

 <your_date>.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT))


0 commentaires