java.time.LocalTime.withMinute()方法的使用及代码示例

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

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

LocalTime.withMinute介绍

[英]Returns a copy of this LocalTime with the minute-of-hour value altered.

This instance is immutable and unaffected by this method call.
[中]返回此LocalTime的副本,更改了小时分钟值。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

@Test
public void testTruncateTime()
{
  LocalTime result = TIME;
  result = result.withNano(0);
  assertFunction("date_trunc('second', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withSecond(0);
  assertFunction("date_trunc('minute', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withMinute(0);
  assertFunction("date_trunc('hour', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
}

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

/**
 * Returns a copy of this {@code OffsetTime} with the minute-of-hour value altered.
 * <p>
 * The offset does not affect the calculation and will be the same in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param minute  the minute-of-hour to set in the result, from 0 to 59
 * @return an {@code OffsetTime} based on this time with the requested minute, not null
 * @throws DateTimeException if the minute value is invalid
 */
public OffsetTime withMinute(int minute) {
  return with(time.withMinute(minute), offset);
}

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

/**
 * Returns a copy of this {@code LocalDateTime} with the minute-of-hour value altered.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param minute  the minute-of-hour to set in the result, from 0 to 59
 * @return a {@code LocalDateTime} based on this date-time with the requested minute, not null
 * @throws DateTimeException if the minute value is invalid
 */
public LocalDateTime withMinute(int minute) {
  LocalTime newTime = time.withMinute(minute);
  return with(date, newTime);
}

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

public static LocalTime roundUpMinutes(LocalTime time, int step) {
  int mins = time.getMinute();
  time = time.withSecond(0).withNano(0);
  if (mins % step == 0) return time;
  if (60 % step != 0) throw new IllegalArgumentException("Invalid step: " + step);
  mins = mins + step - (mins % step);
  return mins < 60 ? time.withMinute(mins) : time.plusHours(1).withMinute(mins - 60);
}

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

@Override
public LocalDateTime getAsObject(FacesContext arg0, UIComponent arg1, String value) {
  if (value == null) {
    return null;
  }
  try {
    return LocalDateTime.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
  } catch (Exception ex) {
    try {
      return LocalDateTime.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
    } catch (Exception ex2) {
      LocalDate localDate = LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
      LocalTime localTime = LocalTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
      return LocalDateTime.of(localDate, localTime);
    }
  }
}

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

public static LocalTime roundDownMinutes(LocalTime time, int step) {
  int mins = time.getMinute();
  time = time.withSecond(0).withNano(0);
  if (mins % step == 0) return time;
  if (60 % step != 0) throw new IllegalArgumentException("Invalid step: " + step);
  return time.withMinute(mins - (mins % step));
}

代码示例来源:origin: com.haulmont.cuba/cuba-web-widgets

protected LocalTime applyResolutionToValue(LocalTime value) {
  if (value == null) {
    return null;
  }
  LocalTime result = LocalTime.MIDNIGHT;
  List<TimeResolution> resolutions = getResolutionsHigherOrEqualTo(getResolution())
      .collect(Collectors.toList());
  for (TimeResolution resolution : resolutions) {
    switch (resolution) {
      case HOUR:
        result = result.withHour(value.getHour());
        break;
      case MINUTE:
        result = result.withMinute(value.getMinute());
        break;
      case SECOND:
        result = result.withSecond(value.getSecond());
        break;
      default:
        throw new IllegalArgumentException("Cannot detect resolution type");
    }
  }
  return result;
}

代码示例来源:origin: io.prestosql/presto-main

@Test
public void testTruncateTime()
{
  LocalTime result = TIME;
  result = result.withNano(0);
  assertFunction("date_trunc('second', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withSecond(0);
  assertFunction("date_trunc('minute', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withMinute(0);
  assertFunction("date_trunc('hour', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
}

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

@Test
public void testTruncateTime()
{
  LocalTime result = TIME;
  result = result.withNano(0);
  assertFunction("date_trunc('second', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withSecond(0);
  assertFunction("date_trunc('minute', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
  result = result.withMinute(0);
  assertFunction("date_trunc('hour', " + TIME_LITERAL + ")", TimeType.TIME, toTime(result));
}

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

case SECOND_OF_MINUTE: return withSecond((int) newValue);
case SECOND_OF_DAY: return plusSeconds(newValue - toSecondOfDay());
case MINUTE_OF_HOUR: return withMinute((int) newValue);
case MINUTE_OF_DAY: return plusMinutes(newValue - (hour * 60 + minute));
case HOUR_OF_AMPM: return plusHours(newValue - (hour % 12));

相关文章