java.time.LocalDateTime.getMonth()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(174)

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

LocalDateTime.getMonth介绍

[英]Gets the month-of-year field using the Month enum.

This method returns the enum Month for the month. This avoids confusion as to what int values mean. If you need access to the primitive int value then the enum provides the Month#getValue().
[中]使用月份枚举获取“月份”字段。
此方法返回当月的枚举月份。这避免了对int值的含义的混淆。如果需要访问原语int值,则枚举将提供Month#getValue()。

代码示例

代码示例来源:origin: org.assertj/assertj-core

/**
 * Returns true if both datetime are in the same year and month, false otherwise.
 *
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year and month, false otherwise
 */
private static boolean haveSameYearAndMonth(LocalDateTime actual, LocalDateTime other) {
 return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Returns true if both datetime are in the same year and month, false otherwise.
 *
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year and month, false otherwise
 */
private static boolean haveSameYearAndMonth(LocalDateTime actual, LocalDateTime other) {
 return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();
}

代码示例来源:origin: apache/usergrid

public void incrementNotificationCounter(String status){
  em.incrementAggregateCounters( null,null,null,"counters.notifications."+notification.getUuid()+"."+status,1 );
  LocalDateTime localDateTime = LocalDateTime.now();
  StringBuilder currentDate = new StringBuilder(  );
  currentDate.append( "counters.notifications.aggregate."+status+"." );
  currentDate.append( localDateTime.getYear()+"." );
  currentDate.append( localDateTime.getMonth()+"." );
  currentDate.append( localDateTime.getDayOfMonth()+"." );
  currentDate.append( localDateTime.getMinute() );
  em.incrementAggregateCounters( null,null,null,currentDate.toString(),1 );
}

代码示例来源:origin: SeanDragon/protools

/**
 * 获取月份对象
 *
 * @return 对象
 */
public Month getMonthObj() {
  return this.localDateTime.getMonth();
}

代码示例来源:origin: apache/usergrid

public void verifyNotificationCounter(Notification notification,String status,Long timestamp, int expected){
  Results countersResults = app.getEntityManager().getAggregateCounters( null,null,null,"counters.notifications."+notification.getUuid()+"."+status,
    CounterResolution.ALL,timestamp,System.currentTimeMillis(),false ) ;
  assertEquals( 1, countersResults.getCounters().size() );
  if(expected > 0) {
    assertEquals( expected, countersResults.getCounters().get( 0 ).getValues().get( 0 ).getValue() );
  }else if (expected == 0){
    assertEquals( 0,countersResults.getCounters().get( 0 ).getValues().size());
  }
  LocalDateTime localDateTime = LocalDateTime.now();
  StringBuilder currentDate = new StringBuilder(  );
  currentDate.append( "counters.notifications.aggregate."+status+"." );
  currentDate.append( localDateTime.getYear()+"." );
  currentDate.append( localDateTime.getMonth()+"." );
  currentDate.append( localDateTime.getDayOfMonth()); //+"." );
  countersResults = app.getEntityManager().getAggregateCounters( null,null,null,currentDate.toString(),
    CounterResolution.ALL,timestamp,System.currentTimeMillis(),false ) ;
  //checks to see that it exists
  assertEquals( 1, countersResults.getCounters().size() );
  if(expected > 0) {
    assertEquals( expected, countersResults.getCounters().get( 0 ).getValues().get( 0 ).getValue() );
  }
  else if (expected == 0){
    assertEquals( 0,countersResults.getCounters().get( 0 ).getValues().size());
  }
}

代码示例来源:origin: oblac/jodd

@Test
void testSet() {
  JulianDate jdt = JulianDate.of(2008, 12, 20, 10, 44, 55, 0);
  JulianDate jdt2 = JulianDate.of(jdt.integer - 1, jdt.fraction);
  assertEquals(jdt.toLocalDateTime().getYear(), jdt2.toLocalDateTime().getYear());
  assertEquals(jdt.toLocalDateTime().getMonth(), jdt2.toLocalDateTime().getMonth());
  assertEquals(jdt.toLocalDateTime().getDayOfMonth() - 1, jdt2.toLocalDateTime().getDayOfMonth());
  assertEquals(jdt.toLocalDateTime().getHour(), jdt2.toLocalDateTime().getHour());
  assertEquals(jdt.toLocalDateTime().getMinute(), jdt2.toLocalDateTime().getMinute());
  assertEquals(jdt.toLocalDateTime().getSecond(), jdt2.toLocalDateTime().getSecond(), 0.0001);
}

代码示例来源:origin: Vazkii/Botania

@Override
  public void init(FMLInitializationEvent event) {
    ColorHandler.init();
    initAuxiliaryRender();

    ModChallenges.init();

    if(ConfigHandler.boundBlockWireframe)
      MinecraftForge.EVENT_BUS.register(BoundTileRenderer.class);

    if(ConfigHandler.useAdaptativeConfig)
      MinecraftForge.EVENT_BUS.register(AdaptorNotifier.class);
//        if(ConfigHandler.versionCheckEnabled)
//            VersionChecker.init();

    if(ConfigHandler.enableSeasonalFeatures) {
      LocalDateTime now = LocalDateTime.now();
      if (now.getMonth() == Month.DECEMBER && now.getDayOfMonth() >= 16 || now.getMonth() == Month.JANUARY && now.getDayOfMonth() <= 2)
        jingleTheBells = true;
      if(now.getMonth() == Month.OCTOBER)
        dootDoot = true;
    }

    TileEntityItemStackRenderer.instance = new RenderTilePylon.ForwardingTEISR(TileEntityItemStackRenderer.instance);

    ClientRegistry.registerKeyBinding(ClientProxy.CORPOREA_REQUEST);
  }

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

ZoneOffset.UTC);
assertThat(c3DateTime.getYear()).isEqualTo(2014);
assertThat(c3DateTime.getMonth()).isEqualTo(Month.SEPTEMBER);
assertThat(c3DateTime.getDayOfMonth()).isEqualTo(8);
assertThat(c3DateTime.getHour()).isEqualTo(17);

代码示例来源:origin: Vazkii/Botania

if(now.getMonth() == Month.NOVEMBER && now.getDayOfMonth() == 22)
  buttonList.add(new GuiButtonDoot(-99, left + 100, top + 12));

代码示例来源:origin: com.liumapp.qtools.date/qtools-date

/**
 * 获取月份对象
 *
 * @return 对象
 */
public Month getMonthObj() {
  return this.localDateTime.getMonth();
}

代码示例来源:origin: mulesoft/mule

private void assertSimpleProperties(HeisenbergExtension heisenberg) {
 assertThat(heisenberg.getPersonalInfo().getName(), equalTo(HEISENBERG));
 assertThat(heisenberg.getPersonalInfo().getAge(), equalTo(Integer.valueOf(AGE)));
 List<String> enemies = heisenberg.getEnemies();
 assertThat(enemies, notNullValue());
 assertThat(enemies.size(), equalTo(2));
 assertThat(enemies.get(0), equalTo(GUSTAVO_FRING));
 assertThat(enemies.get(1), equalTo(HANK));
 assertTrue(heisenberg.isCancer());
 assertThat(heisenberg.getInitialHealth(), is(INITIAL_HEALTH));
 assertThat(heisenberg.getEndingHealth(), is(FINAL_HEALTH));
 assertThat(heisenberg.getFirstEndevour(), containsString(FIRST_ENDEVOUR));
 assertThat(heisenberg.getLabAddress(), is(LAB_ADDRESS));
 Calendar dayOfBirth = Calendar.getInstance();
 dayOfBirth.setTime(heisenberg.getPersonalInfo().getDateOfBirth());
 // only compare year to avoid timezone related flakyness
 assertThat(dayOfBirth.get(YEAR), equalTo(getDateOfBirth().get(YEAR)));
 assertThat(heisenberg.getPersonalInfo().getDateOfDeath().get(YEAR), equalTo(getDateOfDeath().get(YEAR)));
 assertThat(heisenberg.getPersonalInfo().getDateOfConception().getYear(),
       is(getDateOfConception().getYear()));
 assertThat(heisenberg.getPersonalInfo().getDateOfConception().getMonth(),
       is(getDateOfConception().getMonth()));
 assertThat(heisenberg.getMoney(), equalTo(new BigDecimal(MONEY)));
}

代码示例来源:origin: org.assertj/assertj-core-java8

/**
 * Returns true if both datetime are in the same year and month, false otherwise.
 * 
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year and month, false otherwise
 */
private static boolean haveSameYearAndMonth(LocalDateTime actual, LocalDateTime other) {
 return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();
}

代码示例来源:origin: jzyong/game-server

/**@
 * 获取一月最小的天数
 *
 * @return
 */
public static int getMinDaysOfMonth() {
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault()).getMonth().minLength();
}

代码示例来源:origin: com.github.redhatqe.byzantine/byzantine

public static String makeTimeStamp(String base, String end) {
  // Create a timestamped file polarize-config-<timestamp>.xml in backup from polarize-config.xml
  LocalDateTime now = LocalDateTime.now();
  if (!base.equals(""))
    base += "-";
  String timestamp = "%s%s-%s-%d-%d-%d-%d-%d";
  timestamp = String.format(timestamp, base, now.getMonth().toString(), now.getDayOfMonth(), now.getYear(),
      now.getHour(), now.getMinute(), now.getSecond(), now.getNano());
  return timestamp.trim() + end;
}

代码示例来源:origin: stackoverflow.com

Instant timestamp;
...
LocalDateTime ldt = LocalDateTime.ofInstant(timestamp, ZoneId.systemDefault());
System.out.printf("%s %d %d at %d:%d%n", ldt.getMonth(), ldt.getDayOfMonth(),
         ldt.getYear(), ldt.getHour(), ldt.getMinute());

代码示例来源:origin: org.jadira.usertype/usertype.core

@Override
public MonthDay fromNonNullValue(Timestamp value) {
  
  LocalDateTime ldt = value.toLocalDateTime();
  return MonthDay.of(ldt.getMonth(), ldt.getDayOfMonth());
}

代码示例来源:origin: com.intrbiz.bergamot/bergamot-timerange

@Override
public LocalDateTime computeNextStartTime(Clock clock)
{
  LocalDateTime next = super.computeNextStartTime(clock);
  if (next == null) return null;
  // set the day of month
  int dom = this.dayOfMonth > 0 ? this.dayOfMonth : (next.getMonth().maxLength() + this.dayOfMonth + 1);
  next = next.withDayOfMonth(dom);
  // is it next month
  if (! next.isAfter(LocalDateTime.now(clock))) next = next.plusMonths(1);
  // check the date is valid
  return (next.isAfter(LocalDateTime.now(clock))) ? next : null;
}

代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core

/**
 * 取得当季度第一天
 *
 * @return LocalDateHelper
 */
public LocalDateTimeHelper getFirstDayOfQuarter() {
 return LocalDateTimeHelper
   .of(localDateTime.withMonth(localDateTime.getMonth().firstMonthOfQuarter().getValue())
     .with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}

代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web

/**
 * 取得当季度第一天
 *
 * @return LocalDateHelper
 */
public LocalDateTimeHelper getFirstDayOfQuarter() {
 return LocalDateTimeHelper
   .of(localDateTime.withMonth(localDateTime.getMonth().firstMonthOfQuarter().getValue())
     .with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}

代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web

/**
 * 取得下季度第一天
 *
 * @return LocalDateHelper
 */
public LocalDateTimeHelper getFirstDayOfNextQuarter() {
 return LocalDateTimeHelper
   .of(localDateTime
     .withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(3).getValue())
     .with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}

相关文章

LocalDateTime类方法