本文整理匯總了Java中java.time.LocalDate.getYear方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.getYear方法的具體用法?Java LocalDate.getYear怎麽用?Java LocalDate.getYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.getYear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_parse_resolve_localizedWom
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(womField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " ::" + str + "::" + i);
date = date.plusDays(1);
}
}
示例2: test_previous
import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_previous() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
} else {
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 8);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 24);
}
}
}
}
}
示例3: test_parse_resolve_localizedWoyDow_lenient
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(woyField).appendLiteral(':')
.appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(dowField);
for (int j = woy - 60; j < woy + 60; j++) {
String str = date.getYear() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
示例4: calcDiasTrabUltimoMes
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Calcula o total de dias trabalhos no último mês
*
* @param dataSaida Referente ao último dia trabalhado do funcionário.
* @return O total de dias trabalhados no último mês.
*/
public int calcDiasTrabUltimoMes(LocalDate dataSaida) {
int totDiasTrabUltMes = 0;
int mesFim = dataSaida.getMonthValue();
int anoFim = dataSaida.getYear();
LocalDate primeiroDiaMes = LocalDate.of(anoFim, mesFim, 1);
totDiasTrabUltMes = calcDiferDias(primeiroDiaMes, dataSaida);
/* Acrescento mais um dia na váriavel, isto é aplicado para que a contagem
* de dias fique correta. Por exemplo: Se funcionário trabalhou do dia 01
* até o dia 05, o totalDiasTrabalhados seria de 04 dias, sendo o correto
* seriam 05 (Dia 01, Dia 02, Dia 03, Dia 04 e Dia 05)*/
totDiasTrabUltMes += 1;
return totDiasTrabUltMes;
}
示例5: test_parse_resolve_localizedWoyDow
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(woyField).appendLiteral(':')
.appendValue(dowField).toFormatter();
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(woyField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
示例6: test_next
import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_next() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff > 0 && dayDiff < 8);
} else {
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
示例7: test_parse_resolve_localizedWomDow_lenient
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int wom = date.get(womField);
int dow = date.get(dowField);
for (int j = wom - 10; j < wom + 10; j++) {
String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
示例8: test_parse_resolve_localizedWomDow
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 15; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(dowField).toFormatter();
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(womField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
示例9: test_previousOrCurrent
import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_previousOrCurrent() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff <= 0 && dayDiff > -7);
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
} else {
assertFalse(date.getDayOfWeek() == dow);
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 7);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 25);
}
}
}
}
}
示例10: GetLocalDate
import java.time.LocalDate; //導入方法依賴的package包/類
private static DateObjects GetLocalDate() {
final Date date = new Date();
final LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
final int year = localDate.getYear();
final int month = localDate.getMonthValue();
final int day = localDate.getDayOfMonth();
return new DateObjects(year, month, day);
}
示例11: toPrivateJapaneseDate
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* Returns a {@code LocalGregorianCalendar.Date} converted from the given {@code isoDate}.
*
* @param isoDate the local date, not null
* @return a {@code LocalGregorianCalendar.Date}, not null
*/
private static LocalGregorianCalendar.Date toPrivateJapaneseDate(LocalDate isoDate) {
LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null);
sun.util.calendar.Era sunEra = JapaneseEra.privateEraFrom(isoDate);
int year = isoDate.getYear();
if (sunEra != null) {
year -= sunEra.getSinceDate().getYear() - 1;
}
jdate.setEra(sunEra).setYear(year).setMonth(isoDate.getMonthValue()).setDayOfMonth(isoDate.getDayOfMonth());
JapaneseChronology.JCAL.normalize(jdate);
return jdate;
}
示例12: test_loop
import java.time.LocalDate; //導入方法依賴的package包/類
public void test_loop() {
// loop round at least one 400 year cycle, including before 1970
LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960
int year = 1960;
int wby = 1960;
int weekLen = 52;
int week = 1;
while (date.getYear() < 2400) {
DayOfWeek loopDow = date.getDayOfWeek();
if (date.getYear() != year) {
year = date.getYear();
}
if (loopDow == MONDAY) {
week++;
if ((week == 53 && weekLen == 52) || week == 54) {
week = 1;
LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
wby++;
}
}
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
date = date.plusDays(1);
}
}
示例13: test_parse_resolve_localizedWoy_lenient
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(woyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(DAY_OF_WEEK);
for (int j = woy - 60; j < woy + 60; j++) {
String str = date.getYear() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
示例14: test_date_parse
import java.time.LocalDate; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
TemporalAccessor parsed = f.parse(text, pos);
assertEquals(pos.getIndex(), text.length());
assertEquals(pos.getErrorIndex(), -1);
assertEquals(LocalDate.from(parsed), date);
}
示例15: formatsFullNominalPublicationDate
import java.time.LocalDate; //導入方法依賴的package包/類
@Test
@UseDataProvider("validDates")
public void formatsFullNominalPublicationDate(final LocalDate referenceDate) throws Exception {
final RestrictableDate restrictableDate = RestrictableDate.fullDateFrom(referenceDate);
final String expectedFormattedDate =
referenceDate.getDayOfMonth()
+ " " + referenceDate.getMonth().getDisplayName(TextStyle.SHORT, Locale.UK)
+ " " + referenceDate.getYear();
testRestrictableDateFormatting(restrictableDate, expectedFormattedDate);
}