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

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

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

LocalDateTime.getDayOfWeek介绍

[英]Gets the day-of-week field, which is an enum DayOfWeek.

This method returns the enum DayOfWeek for the day-of-week. This avoids confusion as to what int values mean. If you need access to the primitive int value then the enum provides the DayOfWeek#getValue().

Additional information can be obtained from the DayOfWeek. This includes textual names of the values.
[中]获取星期天字段,该字段是枚举DayOfWeek。
此方法返回星期几的枚举DayOfWeek。这避免了对int值的含义的混淆。如果需要访问原语int值,则枚举提供DayOfWeek#getValue()。
更多信息可从DayOfWeek获得。这包括值的文本名称。

代码示例

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

public int getDayOfWeek() {
 return localDateTime.getDayOfWeek().plus(1).getValue();
}

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

LocalDateTime endTime = LocalDateTime.now().plus(remainingSeconds, ChronoUnit.SECONDS);
LocalDateTime currentTime = LocalDateTime.now();
if (endTime.getDayOfWeek() != currentTime.getDayOfWeek())
  sb.append(endTime.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())).append(" ");

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

/**
 * 获取天在这周的对象
 *
 * @return 对象
 */
public DayOfWeek getDayOfWeekObj() {
  return this.localDateTime.getDayOfWeek();
}

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

/**
 * 获取天在这周的次序
 *
 * @return 天
 */
public int getDayOfWeek() {
  return this.localDateTime.getDayOfWeek().getValue();
}

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

/**
 * 获取天在这周的对象
 *
 * @return 对象
 */
public DayOfWeek getDayOfWeekObj() {
  return this.localDateTime.getDayOfWeek();
}

代码示例来源:origin: espertechinc/esper

public Object evaluateInternal(LocalDateTime ldt) {
  return ldt.getDayOfWeek();
}

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

LocalDateTime now = LocalDateTime.now();
boolean isBetween = false;
switch (now.getDayOfWeek()) {
  case FRIDAY:
  case SATURDAY:
  case SUNDAY:
    LocalDateTime lastFriday = getLastFriday(now);
    LocalDateTime nextSunday = getNextSunday(now);
    isBetween = isBetween(now, lastFriday, nextSunday);
    System.out.println(lastFriday + " - " + nextSunday + ": " + end);
    break;
}

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

/**
 * 获取传入毫秒的星期 1-7
 *
 * @param time
 * @return
 */
public static int getDayOfWeek(long time) {
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()).getDayOfWeek().getValue();
}

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

DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHH" );
LocalDateTime start = LocalDateTime.parse( "2016010123" , formatter );
// If on a weekend, move to first moment of Monday.
if( start.getDayOfWeek().equals( DayOfWeek.SATURDAY ) {
  start = start.plusDays( 2 ).toLocalDate().atStartOfDay(); 
}
if( start.getDayOfWeek().equals( DayOfWeek.SUNDAY ) {
  start = start.plusDays( 1 ).toLocalDate().atStartOfDay(); 
}

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

LocalDateTime stop = LocalDateTime.parse( "2016010723" , formatter );
// If on a weekend, move to first moment of Monday.
if( stop.getDayOfWeek().equals( DayOfWeek.SATURDAY ) {
  stop = stop.plusDays( 2 ).toLocalDate().atStartOfDay(); 
}
if( stop.getDayOfWeek().equals( DayOfWeek.SUNDAY ) {
  stop = stop.plusDays( 1 ).toLocalDate().atStartOfDay(); 
}

代码示例来源:origin: com.yahoo.vespa/config-model-api

/** Returns whether the given instant is in this time window */
public boolean includes(Instant instant) {
  LocalDateTime dt = LocalDateTime.ofInstant(instant, zone);
  return days.contains(dt.getDayOfWeek()) && hours.contains(dt.getHour());
}

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

/**
 * 获取天在这周的次序
 *
 * @return 天
 */
public int getDayOfWeek() {
  return this.localDateTime.getDayOfWeek().getValue();
}

代码示例来源:origin: kittylyst/javanut6-examples

public Set<Reminder> getRemindersFor(DayOfWeek dayOfWeek) {
  return reminders.stream()
      .filter(p -> p.getTime().getDayOfWeek() == dayOfWeek)
      .collect(Collectors.toSet());
}

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

LocalDateTime date = LocalDateTime.now();
 do {
   date = date.plusDays(1);
 } while(date.getDayOfWeek().getValue() >= 5);
 String nextDayName = date.format(DateTimeFormatter.ofPattern("EEEE"));

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

/**
 * 获取系统当前的星期 1-7
 *
 * @return
 */
public static int getDayOfWeek() {
  return LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault()).getDayOfWeek().getValue();
}

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

/**@
 * 返回当周第一天格式
 *
 * @param formatter
 * @return
 */
public static String getNowWeekMondayFormat(DateTimeFormatter formatter) {
  LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
  ldt = LocalDateTime.of(ldt.minusDays(ldt.getDayOfWeek().getValue() - 1).toLocalDate(), LocalTime.MIN);
  return ldt.format(formatter);
}

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

LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime dateResult;
boolean shouldReturnLastMonday = (currentTime.getDayOfWeek() != DayOfWeek.MONDAY) ||
                 (currentTime.getDayOfWeek() != DayOfWeek.MONDAY && currentTime.getHour() < 2);
if(shouldReturnLastMonday) {
  dateResult = currentTime.minus(currentTime.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue(), ChronoUnit.DAYS)
      .minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
      .plus(2, ChronoUnit.HOURS);
} else {
  dateResult = currentTime.minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
      .plus(2,ChronoUnit.HOURS);
}

代码示例来源:origin: kittylyst/javanut6-examples

public Set<Reminder> getRemindersOnDayBefore(DayOfWeek dayOfWeek, int hour, int minute) {
  return reminders.stream()
      .filter(p -> p.getTime().getDayOfWeek() == dayOfWeek)
      .filter(p -> p.getTime().toLocalTime().isBefore(LocalTime.of(hour, minute)))
      .collect(Collectors.toSet());
}

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

int countWeekdays = 0;
LocalDateTime firstMomentOfSomeDay = firstMomentOfDayAfterStart
while( firstMomentOfSomeDay.isBefore( firstMomentOfDayOfStop ) ) {
  DayOfWeek dayOfWeek = firstMomentOfSomeDay.getDayOfWeek();
  if( dayOfWeek.equals( DayOfWeek.SATURDAY ) || dayOfWeek.equals( DayOfWeek.SUNDAY ) ) {
    // ignore this day.
  } else {
    countWeekdays ++ ; // Tally another weekday.
  }
  // Set up the next loop.
  firstMomentOfSomeDay = firstMomentOfSomeDay.plusDays( 1 );
}

代码示例来源:origin: waterguo/antsdb

@Override
public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) {
  long pValue = this.parameters.get(0).eval(ctx, heap, params, pRecord);
  if (pValue == 0) {
    return 0;
  }
  pValue = AutoCaster.toTimestamp(heap, pValue);
  Timestamp ts = FishTimestamp.get(heap, pValue);
  int weekday = ts.toLocalDateTime().getDayOfWeek().getValue()-1;
  return Int4.allocSet(heap, weekday);
}

相关文章

LocalDateTime类方法