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

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

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

LocalDateTime.getMonthValue介绍

[英]Gets the month-of-year field from 1 to 12.

This method returns the month as an int from 1 to 12. Application code is frequently clearer if the enum Monthis used by calling #getMonth().
[中]获取从1到12的月份字段。
此方法将月份返回为1到12之间的整数。如果调用#getMonth()使用枚举月,则应用程序代码通常更清晰。

代码示例

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

public int getMonth() {
 return localDateTime.getMonthValue();
}

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

LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
int hour = now.getHour();
int minute = now.getMinute();
int second = now.getSecond();
int millis = now.get(ChronoField.MILLI_OF_SECOND); // Note: no direct getter available.

System.out.printf("%d-%02d-%02d %02d:%02d:%02d.%03d", year, month, day, hour, minute, second, millis);

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g,
    SerializerProvider provider) throws IOException
{
  g.writeNumber(value.getYear());
  g.writeNumber(value.getMonthValue());
  g.writeNumber(value.getDayOfMonth());
  g.writeNumber(value.getHour());
  g.writeNumber(value.getMinute());
  final int secs = value.getSecond();
  final int nanos = value.getNano();
  if ((secs > 0) || (nanos > 0)) {
    g.writeNumber(secs);
    if (nanos > 0) {
      if (useNanoseconds(provider)) {
        g.writeNumber(nanos);
      } else {
        g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
  }
}

代码示例来源:origin: alibaba/fastjson

if (text.length() == 23) {
  LocalDateTime localDateTime = LocalDateTime.parse(text);
  localDate = LocalDate.of(localDateTime.getYear(), localDateTime.getMonthValue(),
      localDateTime.getDayOfMonth());
} else {

代码示例来源:origin: rubenlagus/TelegramBots

private static String dateFormatterForLogs(LocalDateTime dateTime) {
  String dateString = "[";
  dateString += dateTime.getDayOfMonth() + "_";
  dateString += dateTime.getMonthValue() + "_";
  dateString += dateTime.getYear() + "_";
  dateString += dateTime.getHour() + ":";
  dateString += dateTime.getMinute() + ":";
  dateString += dateTime.getSecond();
  dateString += "] ";
  return dateString;
}

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

@Override
public Date unmarshal(String date) throws Exception {
  final LocalDateTime now = LocalDateTime.now();
  final DateTimeFormatter parser = new DateTimeFormatterBuilder().appendPattern(DEFAULT_TIME_FORMAT)
      .parseDefaulting(ChronoField.YEAR, now.getYear())
      .parseDefaulting(ChronoField.MONTH_OF_YEAR, now.getMonthValue())
      .parseDefaulting(ChronoField.DAY_OF_MONTH, now.getDayOfMonth())
      .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0)
      .toFormatter(Locale.US);
  final LocalDateTime parsedDateTime = LocalDateTime.parse(date, parser);
  return Date.from(parsedDateTime.toInstant(ZONE_ID.getRules().getOffset(now)));
}

代码示例来源:origin: com.alibaba/fastjson

if (text.length() == 23) {
  LocalDateTime localDateTime = LocalDateTime.parse(text);
  localDate = LocalDate.of(localDateTime.getYear(), localDateTime.getMonthValue(),
      localDateTime.getDayOfMonth());
} else {

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

@Override
public Date unmarshal(String date) throws Exception {
  final LocalDateTime now = LocalDateTime.now();
  final DateTimeFormatter parser = new DateTimeFormatterBuilder().appendPattern(DEFAULT_DATE_TIME_FORMAT)
      .parseDefaulting(ChronoField.YEAR, now.getYear())
      .parseDefaulting(ChronoField.MONTH_OF_YEAR, now.getMonthValue())
      .parseDefaulting(ChronoField.DAY_OF_MONTH, now.getDayOfMonth())
      .parseDefaulting(ChronoField.HOUR_OF_DAY, now.getHour())
      .parseDefaulting(ChronoField.MINUTE_OF_HOUR, now.getMinute())
      .parseDefaulting(ChronoField.SECOND_OF_MINUTE, now.getSecond())
      .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0)
      .toFormatter(Locale.US);
  final LocalDateTime parsedDateTime = LocalDateTime.parse(date, parser);
  return Date.from(parsedDateTime.toInstant(ZONE_ID.getRules().getOffset(now)));
}

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

/**
 * 获取月份
 *
 * @return 月
 */
public int getMonth() {
  return this.localDateTime.getMonthValue();
}

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

@SuppressWarnings("deprecation")
@Test
public void shouldReturnLocalDateTimeInstanceWhenConvertingUtilTimeToLocalDateTime() {
  LocalDateTime now = LocalDateTime.now();
  java.util.Date date = new java.util.Date(now.getYear()-1900,now.getMonthValue()-1,now.getDayOfMonth(),
                       now.getHour(),now.getMinute(),now.getSecond()); // 0 nanos!
  assertThat(Conversions.toLocalDateTime(date)).isEqualTo(now.withNano(0));
}

代码示例来源:origin: prestodb/presto

private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g,
    SerializerProvider provider) throws IOException
{
  g.writeNumber(value.getYear());
  g.writeNumber(value.getMonthValue());
  g.writeNumber(value.getDayOfMonth());
  g.writeNumber(value.getHour());
  g.writeNumber(value.getMinute());
  final int secs = value.getSecond();
  final int nanos = value.getNano();
  if ((secs > 0) || (nanos > 0)) {
    g.writeNumber(secs);
    if (nanos > 0) {
      if (useNanoseconds(provider)) {
        g.writeNumber(nanos);
      } else {
        g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
  }
}

代码示例来源:origin: jtablesaw/tablesaw

@Test
public void testConvertMillisSinceEpoch() {
  long millis = 1503952123189L;
  LongColumn dc = LongColumn.create("test");
  dc.append(millis);
  DateTimeColumn column2 = dc.asDateTimes(ZoneOffset.UTC);
  assertEquals(1, column2.size());
  assertEquals(2017, column2.get(0).getYear());
  assertEquals(8, column2.get(0).getMonthValue());
  assertEquals(28, column2.get(0).getDayOfMonth());
  assertEquals(20, column2.get(0).getHour());
  long[] millisArr = column2.asEpochMillisArray();
  assertEquals(1, millisArr.length);
  assertEquals(millis, millisArr[0]);
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
protected int getDatePart(LocalDateTime date,
    DateTimeResolution resolution) {
  LocalDateTime value = date;
  if (value == null) {
    value = LocalDateTime.of(1, 1, 1, 0, 0);
  }
  switch (resolution) {
  case DAY:
    return value.getDayOfMonth();
  case MONTH:
    return value.getMonthValue();
  case YEAR:
    return value.getYear();
  case HOUR:
    return value.getHour();
  case MINUTE:
    return value.getMinute();
  case SECOND:
    return value.getSecond();
  default:
    assert false : "Unexpected resolution argument " + resolution;
    return -1;
  }
}

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

@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final LocalDateTime localDateTime) {
  output.writeInt(localDateTime.getYear());
  output.writeInt(localDateTime.getMonthValue());
  output.writeInt(localDateTime.getDayOfMonth());
  output.writeInt(localDateTime.getHour());
  output.writeInt(localDateTime.getMinute());
  output.writeInt(localDateTime.getSecond());
  output.writeInt(localDateTime.getNano());
}

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

/**
 * 获取传入毫秒的月份 1-12
 *
 * @param time
 * @return
 */
public static int getMonth(long time) {
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()).getMonthValue();
}

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

/**
 * 获取系统当前月份 1-12
 *
 * @return
 */
public static int getMonth() {
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault()).getMonthValue();
}

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

/**@
 * 判断两个时间是否在同一月
 *
 * @param time1
 * @param time2
 * @return
 */
public static boolean isSameMonth(long time1, long time2) {
  LocalDateTime ldt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault());
  LocalDateTime ldt2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault());
  return ldt1.getYear() == ldt2.getYear() && ldt1.getMonthValue() == ldt2.getMonthValue();
}

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

/**@
 * 判断两个时间是否在同一季度
 *
 * @param time1
 * @param time2
 * @return
 */
public static boolean isSameQuarter(long time1, long time2) {
  LocalDateTime ldt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault());
  LocalDateTime ldt2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault());
  return ldt1.getYear() == ldt2.getYear() && ldt1.getMonthValue() / 4 == ldt2.getMonthValue() / 4;
}

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

private void assertDateTime(LocalDateTime localDateTime) {
 assertEquals(localDateTime.getYear(), YEAR);
 assertEquals(localDateTime.getMonthValue(), MONTH);
 assertEquals(localDateTime.getDayOfMonth(), DAY);
 assertEquals(localDateTime.getHour(), HOUR);
 assertEquals(localDateTime.getMinute(), MINUTE);
 assertEquals(localDateTime.getSecond(), SECOND);
}

代码示例来源:origin: org.mule.runtime/mule-module-extensions-spring-support

private void assertDateTime(LocalDateTime localDateTime) {
 assertEquals(localDateTime.getYear(), YEAR);
 assertEquals(localDateTime.getMonthValue(), MONTH);
 assertEquals(localDateTime.getDayOfMonth(), DAY);
 assertEquals(localDateTime.getHour(), HOUR);
 assertEquals(localDateTime.getMinute(), MINUTE);
 assertEquals(localDateTime.getSecond(), SECOND);
}

相关文章

LocalDateTime类方法