本文整理了Java中java.time.YearMonth.now()
方法的一些代码示例,展示了YearMonth.now()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.now()
方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:now
[英]Obtains the current year-month from the system clock in the default time-zone.
This will query the Clock#systemDefaultZone() in the default time-zone to obtain the current year-month. The zone and offset will be set based on the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
[中]从默认时区的系统时钟获取当前年份月份。
这将查询默认时区中的时钟#systemDefaultZone(),以获取当前年份月份。分区和偏移量将根据时钟中的时区进行设置。
使用此方法将防止使用备用时钟进行测试,因为该时钟是硬编码的。
代码示例来源:origin: jfoenixadmin/JFoenix
YearMonth.from(date) : YearMonth.now());
content.updateValues();
LocalDate date = jfxDatePicker.getValue();
content.displayedYearMonthProperty().set((date != null) ?
YearMonth.from(date) : YearMonth.now());
content.updateValues();
代码示例来源:origin: wildfly/wildfly
assertTrue(immutability.test(WeekFields.ISO));
assertTrue(immutability.test(Year.now()));
assertTrue(immutability.test(YearMonth.now()));
assertTrue(immutability.test(ZoneOffset.UTC));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));
代码示例来源:origin: diffplug/spotless
/** The license that we'd like enforced. */
private LicenseHeaderStep(String licenseHeader, String delimiter, String yearSeparator) {
if (delimiter.contains("\n")) {
throw new IllegalArgumentException("The delimiter must not contain any newlines.");
}
// sanitize the input license
licenseHeader = LineEnding.toUnix(licenseHeader);
if (!licenseHeader.endsWith("\n")) {
licenseHeader = licenseHeader + "\n";
}
this.licenseHeader = licenseHeader;
this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE);
this.hasYearToken = licenseHeader.contains("$YEAR");
if (this.hasYearToken) {
int yearTokenIndex = licenseHeader.indexOf("$YEAR");
this.licenseHeaderBeforeYearToken = licenseHeader.substring(0, yearTokenIndex);
this.licenseHeaderAfterYearToken = licenseHeader.substring(yearTokenIndex + 5, licenseHeader.length());
this.licenseHeaderWithYearTokenReplaced = licenseHeader.replace("$YEAR", String.valueOf(YearMonth.now().getYear()));
this.yearMatcherPattern = Pattern.compile("[0-9]{4}(" + Pattern.quote(yearSeparator) + "[0-9]{4})?");
}
}
代码示例来源:origin: diffplug/spotless
private String currentYear() {
return String.valueOf(YearMonth.now().getYear());
}
代码示例来源:origin: jfoenixadmin/JFoenix
selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());
代码示例来源:origin: EvoSuite/evosuite
public static YearMonth now(Clock clock) {
return YearMonth.now(clock);
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
protected YearMonth getReferenceValue(Clock reference) {
return YearMonth.now( reference );
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
protected YearMonth getReferenceValue(Clock reference) {
return YearMonth.now( reference );
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
protected YearMonth getReferenceValue(Clock reference) {
return YearMonth.now( reference );
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
protected YearMonth getReferenceValue(Clock reference) {
return YearMonth.now( reference );
}
代码示例来源:origin: br.com.jarch/jarch-annotation
@Override
public String getValueInsertTest() {
return YearMonth.now().format(DateTimeFormatter.ofPattern(MMYYYY));
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Obtains the current year-month from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current year-month.
* Specifying the time-zone avoids dependence on the default time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current year-month using the system clock, not null
*/
public static YearMonth now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Obtains the current year-month from the system clock in the default time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in the default
* time-zone to obtain the current year-month.
* The zone and offset will be set based on the time-zone in the clock.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @return the current year-month using the system clock and default time-zone, not null
*/
public static YearMonth now() {
return now(Clock.systemDefaultZone());
}
代码示例来源:origin: diffplug/spotless
@Test
public void testWithNonStandardYearSeparator() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'nebula.kotlin' version '1.0.6'",
" id 'com.diffplug.gradle.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless {",
" kotlin {",
" licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')",
" ktlint()",
" }",
"}");
setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
gradleRunner().withArguments("spotlessApply").build();
assertFile("src/main/kotlin/test.kt").matches(matcher -> {
matcher.startsWith("// License Header 2012, 2014");
});
assertFile("src/main/kotlin/test2.kt").matches(matcher -> {
matcher.startsWith(HEADER_WITH_YEAR.replace("$YEAR", String.valueOf(YearMonth.now().getYear())));
});
}
}
代码示例来源:origin: br.com.jarch/jarch-annotation
@Override
public String getValueCloneTest() {
return YearMonth.now().minusMonths(1).format(DateTimeFormatter.ofPattern(MMYYYY));
}
代码示例来源:origin: br.com.jarch/jarch-annotation
@Override
public String getValueChangeTest() {
return YearMonth.now().minusMonths(2).format(DateTimeFormatter.ofPattern(MMYYYY));
}
代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker
/**
* setSelectedDate, This sets a date that will be marked as "selected" in the calendar, and sets
* the displayed YearMonth to show that date. If the supplied date is null, then the selected
* date will be cleared, and the displayed YearMonth will be set to today's year and month.
*
* Technical note: This is implemented with the following two functions:
* setSelectedDateWithoutShowing() and setSelectedYearMonth().
*/
public void setSelectedDate(LocalDate selectedDate) {
setSelectedDateWithoutShowing(selectedDate);
YearMonth yearMonthToShow
= (selectedDate == null) ? YearMonth.now() : YearMonth.from(selectedDate);
setDisplayedYearMonth(yearMonthToShow);
}
代码示例来源:origin: AnghelLeonard/Hibernate-SpringBoot
public void newRoyalty() {
Royalty royalty = new Royalty();
royalty.setAmount(45.5f);
royalty.setPayedOn(YearMonth.now());
royaltyRepository.save(royalty);
}
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testJavaYearMonth() throws Exception {
java.time.YearMonth value = java.time.YearMonth.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class);
verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.DATE);
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testCharacterToTime() throws Exception {
testConvertFromCharSequence(Instant.now(), DateTimeFormatter.ISO_INSTANT);
testConvertFromCharSequence(LocalDate.now(), DateTimeFormatter.ISO_LOCAL_DATE);
testConvertFromCharSequence(LocalDateTime.now(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
testConvertFromCharSequence(LocalTime.now(), DateTimeFormatter.ISO_LOCAL_TIME);
testConvertFromCharSequence(OffsetDateTime.now(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
testConvertFromCharSequence(OffsetTime.now(), DateTimeFormatter.ISO_OFFSET_TIME);
testConvertFromCharSequence(Year.now(), DateTimeFormatter.ofPattern("yyyy"));
testConvertFromCharSequence(YearMonth.now(), DateTimeFormatter.ofPattern("yyyy-MM"));
testConvertFromCharSequence(ZonedDateTime.now(), DateTimeFormatter.ISO_ZONED_DATE_TIME);
}
内容来源于网络,如有侵权,请联系作者删除!