У меня есть строка в формате «мм/гггг», и я хочу сравнить ее с датой в локальной системе.
Я думал об использовании любого из них: таблица преобразования между моим месяцем и полем МЕСЯЦ в календаре, что-то вроде:
Код: Выделить всё
Calendar cal = Calendar.getInstance();
String date = "07/2014";
String month = date.subString(0, 2);
int monthToCompare;
if (month.equals("01"))
monthToCompare = cal.JANUARY;
if (month.equals("02"))
monthToCompare = cal.FEBRUARY;
...
The other option I've thought of is getting the current Date() and using the before() method. That would mean translating my date to the Date format, but the easy methods to do it are deprecated, I must specify the number of milliseconds and I do not know how to easily do that (taking into consideration leap years, calendar corrections and so on since 1970).
Источник: https://stackoverflow.com/questions/241 ... -is-passed
Мобильная версия