Je suis un nouveau développeur Android. Je voudrais analyser cette date: 2019-02-10T19: 30h00 + 00: 00 à ce format 19:30. P>
4 Réponses :
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.
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)
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()));
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.
Essayez ceci à Kotlin:
<your_date>.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT))