本文整理匯總了Java中java.time.YearMonth.now方法的典型用法代碼示例。如果您正苦於以下問題:Java YearMonth.now方法的具體用法?Java YearMonth.now怎麽用?Java YearMonth.now使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.YearMonth
的用法示例。
在下文中一共展示了YearMonth.now方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: now
import java.time.YearMonth; //導入方法依賴的package包/類
@Test
public void now() {
YearMonth expected = YearMonth.now(Clock.systemDefaultZone());
YearMonth test = YearMonth.now();
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = YearMonth.now(Clock.systemDefaultZone());
test = YearMonth.now();
}
assertEquals(test, expected);
}
示例2: now_ZoneId
import java.time.YearMonth; //導入方法依賴的package包/類
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
YearMonth expected = YearMonth.now(Clock.system(zone));
YearMonth test = YearMonth.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = YearMonth.now(Clock.system(zone));
test = YearMonth.now(zone);
}
assertEquals(test, expected);
}
示例3: now_Clock
import java.time.YearMonth; //導入方法依賴的package包/類
@Test
public void now_Clock() {
Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
YearMonth test = YearMonth.now(clock);
assertEquals(test.getYear(), 2010);
assertEquals(test.getMonth(), Month.DECEMBER);
}
示例4: now_ZoneId_nullZoneId
import java.time.YearMonth; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
YearMonth.now((ZoneId) null);
}
示例5: now_Clock_nullClock
import java.time.YearMonth; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
YearMonth.now((Clock) null);
}