У меня есть следующая функция преобразования:
Код: Выделить всё
public static long convertdatetotimestamp(String datestring, String newdateformat, String olddateformat){
SimpleDateFormat originalFormat = new SimpleDateFormat(olddateformat,Locale.ROOT);
SimpleDateFormat targetFormat = new SimpleDateFormat(newdateformat,Locale.ROOT);
Date date = null;
try {
date = originalFormat.parse(datestring);
String formattedDate = targetFormat.format(date);
Date parsedDate = targetFormat.parse(formattedDate);
long nowMilliseconds = parsedDate.getTime();
return nowMilliseconds;
} catch (ParseException e) {
e.printStackTrace();
return 0;
}
}
Это вызывает следующую ошибку в журнале:
java.text.ParseException: неразбираемая дата: «14:22» (по смещению 6)
Как решить эту проблему? Время указано точно в указанном выше формате.
Подробнее здесь: https://stackoverflow.com/questions/452 ... on-android
Мобильная версия