java.time.YearMonth.now()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中java.time.YearMonth.now()方法的一些代码示例,展示了YearMonth.now()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.now()方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:now

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

  1. YearMonth.from(date) : YearMonth.now());
  2. content.updateValues();
  3. LocalDate date = jfxDatePicker.getValue();
  4. content.displayedYearMonthProperty().set((date != null) ?
  5. YearMonth.from(date) : YearMonth.now());
  6. content.updateValues();

代码示例来源:origin: wildfly/wildfly

  1. assertTrue(immutability.test(WeekFields.ISO));
  2. assertTrue(immutability.test(Year.now()));
  3. assertTrue(immutability.test(YearMonth.now()));
  4. assertTrue(immutability.test(ZoneOffset.UTC));
  5. assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));

代码示例来源:origin: diffplug/spotless

  1. /** The license that we'd like enforced. */
  2. private LicenseHeaderStep(String licenseHeader, String delimiter, String yearSeparator) {
  3. if (delimiter.contains("\n")) {
  4. throw new IllegalArgumentException("The delimiter must not contain any newlines.");
  5. }
  6. // sanitize the input license
  7. licenseHeader = LineEnding.toUnix(licenseHeader);
  8. if (!licenseHeader.endsWith("\n")) {
  9. licenseHeader = licenseHeader + "\n";
  10. }
  11. this.licenseHeader = licenseHeader;
  12. this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE);
  13. this.hasYearToken = licenseHeader.contains("$YEAR");
  14. if (this.hasYearToken) {
  15. int yearTokenIndex = licenseHeader.indexOf("$YEAR");
  16. this.licenseHeaderBeforeYearToken = licenseHeader.substring(0, yearTokenIndex);
  17. this.licenseHeaderAfterYearToken = licenseHeader.substring(yearTokenIndex + 5, licenseHeader.length());
  18. this.licenseHeaderWithYearTokenReplaced = licenseHeader.replace("$YEAR", String.valueOf(YearMonth.now().getYear()));
  19. this.yearMatcherPattern = Pattern.compile("[0-9]{4}(" + Pattern.quote(yearSeparator) + "[0-9]{4})?");
  20. }
  21. }

代码示例来源:origin: diffplug/spotless

  1. private String currentYear() {
  2. return String.valueOf(YearMonth.now().getYear());
  3. }

代码示例来源:origin: jfoenixadmin/JFoenix

  1. selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
  2. selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());

代码示例来源:origin: EvoSuite/evosuite

  1. public static YearMonth now(Clock clock) {
  2. return YearMonth.now(clock);
  3. }

代码示例来源:origin: org.hibernate.validator/hibernate-validator

  1. @Override
  2. protected YearMonth getReferenceValue(Clock reference) {
  3. return YearMonth.now( reference );
  4. }

代码示例来源:origin: org.hibernate.validator/hibernate-validator

  1. @Override
  2. protected YearMonth getReferenceValue(Clock reference) {
  3. return YearMonth.now( reference );
  4. }

代码示例来源:origin: org.hibernate.validator/hibernate-validator

  1. @Override
  2. protected YearMonth getReferenceValue(Clock reference) {
  3. return YearMonth.now( reference );
  4. }

代码示例来源:origin: org.hibernate.validator/hibernate-validator

  1. @Override
  2. protected YearMonth getReferenceValue(Clock reference) {
  3. return YearMonth.now( reference );
  4. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueInsertTest() {
  3. return YearMonth.now().format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains the current year-month from the system clock in the specified time-zone.
  3. * <p>
  4. * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current year-month.
  5. * Specifying the time-zone avoids dependence on the default time-zone.
  6. * <p>
  7. * Using this method will prevent the ability to use an alternate clock for testing
  8. * because the clock is hard-coded.
  9. *
  10. * @param zone the zone ID to use, not null
  11. * @return the current year-month using the system clock, not null
  12. */
  13. public static YearMonth now(ZoneId zone) {
  14. return now(Clock.system(zone));
  15. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains the current year-month from the system clock in the default time-zone.
  3. * <p>
  4. * This will query the {@link Clock#systemDefaultZone() system clock} in the default
  5. * time-zone to obtain the current year-month.
  6. * The zone and offset will be set based on the time-zone in the clock.
  7. * <p>
  8. * Using this method will prevent the ability to use an alternate clock for testing
  9. * because the clock is hard-coded.
  10. *
  11. * @return the current year-month using the system clock and default time-zone, not null
  12. */
  13. public static YearMonth now() {
  14. return now(Clock.systemDefaultZone());
  15. }

代码示例来源:origin: diffplug/spotless

  1. @Test
  2. public void testWithNonStandardYearSeparator() throws IOException {
  3. setFile("build.gradle").toLines(
  4. "plugins {",
  5. " id 'nebula.kotlin' version '1.0.6'",
  6. " id 'com.diffplug.gradle.spotless'",
  7. "}",
  8. "repositories { mavenCentral() }",
  9. "spotless {",
  10. " kotlin {",
  11. " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')",
  12. " ktlint()",
  13. " }",
  14. "}");
  15. setFile("src/main/kotlin/test.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test");
  16. setFile("src/main/kotlin/test2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test");
  17. gradleRunner().withArguments("spotlessApply").build();
  18. assertFile("src/main/kotlin/test.kt").matches(matcher -> {
  19. matcher.startsWith("// License Header 2012, 2014");
  20. });
  21. assertFile("src/main/kotlin/test2.kt").matches(matcher -> {
  22. matcher.startsWith(HEADER_WITH_YEAR.replace("$YEAR", String.valueOf(YearMonth.now().getYear())));
  23. });
  24. }
  25. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueCloneTest() {
  3. return YearMonth.now().minusMonths(1).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: br.com.jarch/jarch-annotation

  1. @Override
  2. public String getValueChangeTest() {
  3. return YearMonth.now().minusMonths(2).format(DateTimeFormatter.ofPattern(MMYYYY));
  4. }

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

  1. /**
  2. * setSelectedDate, This sets a date that will be marked as "selected" in the calendar, and sets
  3. * the displayed YearMonth to show that date. If the supplied date is null, then the selected
  4. * date will be cleared, and the displayed YearMonth will be set to today's year and month.
  5. *
  6. * Technical note: This is implemented with the following two functions:
  7. * setSelectedDateWithoutShowing() and setSelectedYearMonth().
  8. */
  9. public void setSelectedDate(LocalDate selectedDate) {
  10. setSelectedDateWithoutShowing(selectedDate);
  11. YearMonth yearMonthToShow
  12. = (selectedDate == null) ? YearMonth.now() : YearMonth.from(selectedDate);
  13. setDisplayedYearMonth(yearMonthToShow);
  14. }

代码示例来源:origin: AnghelLeonard/Hibernate-SpringBoot

  1. public void newRoyalty() {
  2. Royalty royalty = new Royalty();
  3. royalty.setAmount(45.5f);
  4. royalty.setPayedOn(YearMonth.now());
  5. royaltyRepository.save(royalty);
  6. }
  7. }

代码示例来源:origin: arnaudroger/SimpleFlatMapper

  1. @Test
  2. public void testJavaYearMonth() throws Exception {
  3. java.time.YearMonth value = java.time.YearMonth.now();
  4. java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
  5. newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId));
  6. newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class);
  7. verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli()));
  8. verify(ps).setNull(2, Types.DATE);
  9. }

代码示例来源:origin: arnaudroger/SimpleFlatMapper

  1. @Test
  2. public void testCharacterToTime() throws Exception {
  3. testConvertFromCharSequence(Instant.now(), DateTimeFormatter.ISO_INSTANT);
  4. testConvertFromCharSequence(LocalDate.now(), DateTimeFormatter.ISO_LOCAL_DATE);
  5. testConvertFromCharSequence(LocalDateTime.now(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
  6. testConvertFromCharSequence(LocalTime.now(), DateTimeFormatter.ISO_LOCAL_TIME);
  7. testConvertFromCharSequence(OffsetDateTime.now(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  8. testConvertFromCharSequence(OffsetTime.now(), DateTimeFormatter.ISO_OFFSET_TIME);
  9. testConvertFromCharSequence(Year.now(), DateTimeFormatter.ofPattern("yyyy"));
  10. testConvertFromCharSequence(YearMonth.now(), DateTimeFormatter.ofPattern("yyyy-MM"));
  11. testConvertFromCharSequence(ZonedDateTime.now(), DateTimeFormatter.ISO_ZONED_DATE_TIME);
  12. }

相关文章