val yearMonth = new YearMonth(); val formatter = DateTimeFormat.forPattern("yyyyMM"); val dates = (0 to 5).map { i=>formatter.print(yearMonth.plusMonths(i)).toInt }.toList
/** * Returns a copy of this year-month with the new year and month, checking * to see if a new object is in fact required. * * @param newYear the year to represent, validated from MIN_YEAR to MAX_YEAR * @param newMonth the month-of-year to represent, validated not null * @return the year-month, not null */ private YearMonth with(int newYear, int newMonth) { if (year == newYear && month == newMonth) { return this; } return new YearMonth(newYear, newMonth); }
/** * Returns a copy of this year-month with the new year and month, checking * to see if a new object is in fact required. * * @param newYear the year to represent, validated from MIN_YEAR to MAX_YEAR * @param newMonth the month-of-year to represent, validated not null * @return the year-month, not null */ private YearMonth with(int newYear, int newMonth) { if (year == newYear && month == newMonth) { return this; } return new YearMonth(newYear, newMonth); }
import org.joda.time.YearMonth; import java.util.Locale; public class X { public static void main(String[] s){ for (int i = 1;i<13; i++) { YearMonth md = new YearMonth(1992, i); System.out.println(md.monthOfYear().getAsText(new Locale("ru"))); } } }
YearMonth ym = new YearMonth(); dt = ym.toDateTime(null); System.out.println(dt.dayOfMonth().getMaximumValue());
YearMonth yearMonth = new YearMonth(); yearMonth.toLocalDate(1).dayOfMonth().getMaximumValue();
new LocalDateTime(1980, 1, 1, 0, 0).withFields(new YearMonth(2014, 1))
YearMonth yearMonth = new YearMonth (1970, 1); Interval interval = yearMonth.toInterval(DateTimeZone.UTC); int startSSE = (int) TimeUnit.MILLISECONDS.toSeconds(interval.getStartMillis()); int endSSE = (int) TimeUnit.MILLISECONDS.toSeconds(interval.getEndMillis()); System.out.printf("%d -> %d (%4.6f days)\n", startSSE, endSSE, ((float)(endSSE-startSSE))/(24*60*60));
/** * Obtains an instance of {@code YearMonth} from a year and month. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @return the year-month, not null * @throws DateTimeException if either field value is invalid */ public static YearMonth of(int year, int month) { YEAR.checkValidValue(year); MONTH_OF_YEAR.checkValidValue(month); return new YearMonth(year, month); }
/** * Obtains an instance of {@code YearMonth} from a year and month. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @return the year-month, not null * @throws DateTimeException if either field value is invalid */ public static YearMonth of(int year, int month) { YEAR.checkValidValue(year); MONTH_OF_YEAR.checkValidValue(month); return new YearMonth(year, month); }