org.joda.time.LocalDateTime.withDayOfMonth()方法的使用及代码示例

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

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

LocalDateTime.withDayOfMonth介绍

[英]Returns a copy of this datetime with the day of month field updated.

LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of month changed.
[中]返回此datetime的副本,并更新月日字段。
LocalDateTime是不可变的,因此没有set方法。相反,此方法返回一个新实例,该实例的值为“已更改的月份天数”。

代码示例

代码示例来源:origin: plusonelabs/calendar-widget

/**
 * Implemented based on this answer: http://stackoverflow.com/a/5451245/297710
 */
private DateTime fromAllDayMillis(long millis) {
  String msgLog = "millis=" + millis;
  DateTime fixed;
  try {
    DateTime utcDate = new DateTime(millis, DateTimeZone.UTC);
    LocalDateTime ldt = new LocalDateTime()
        .withYear(utcDate.getYear())
        .withMonthOfYear(utcDate.getMonthOfYear())
        .withDayOfMonth(utcDate.getDayOfMonth())
        .withMillisOfDay(0);
    int hour = 0;
    while (zone.isLocalDateTimeGap(ldt)) {
      Log.v("fixTimeOfAllDayEvent", "Local Date Time Gap: " + ldt + "; " + msgLog);
      ldt = ldt.withHourOfDay(++hour);
    }
    fixed = ldt.toDateTime(zone);
    msgLog += " -> " + fixed;
    if (BuildConfig.DEBUG) {
      Log.v("fixTimeOfAllDayEvent", msgLog);
    }
  } catch (org.joda.time.IllegalInstantException e) {
    throw new org.joda.time.IllegalInstantException(msgLog + " caused by: " + e);
  }
  return fixed;
}

代码示例来源:origin: com.effektif/effektif-workflow-api

@Override
public LocalDateTime resolve(LocalDateTime base) {
 LocalDateTime time = null;
 if (HOUR_OF_DAY.equals(indexUnit)) {
  time = base.withTime(index, 0, 0, 0);
  if (!time.isAfter(base)) {
   return time.plusDays(1);
  }
 } else if (DAY_OF_WEEK.equals(indexUnit)) {
  time = base
    .withDayOfWeek(index)
    .withTime(0, 0, 0, 0);
  if (!time.isAfter(base)) {
   time = time.plusWeeks(1);
  }
 } else if (DAY_OF_MONTH.equals(indexUnit)) {
  time = base
    .withDayOfMonth(index)
    .withTime(0, 0, 0, 0);
  if (!time.isAfter(base)) {
   time = time.plusMonths(1);
  }
 }
 if (atHour!=null) {
  time = time.withTime(atHour, atMinute!=null ? atMinute : 0, 0, 0);
 }
 return time;
}

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

@Override
public LocalDateTime resolve(LocalDateTime base) {
 LocalDateTime time = null;
 if (HOUR_OF_DAY.equals(indexUnit)) {
  time = base.withTime(index, 0, 0, 0);
  if (!time.isAfter(base)) {
   return time.plusDays(1);
  }
 } else if (DAY_OF_WEEK.equals(indexUnit)) {
  time = base
    .withDayOfWeek(index)
    .withTime(0, 0, 0, 0);
  if (!time.isAfter(base)) {
   time = time.plusWeeks(1);
  }
 } else if (DAY_OF_MONTH.equals(indexUnit)) {
  time = base
    .withDayOfMonth(index)
    .withTime(0, 0, 0, 0);
  if (!time.isAfter(base)) {
   time = time.plusMonths(1);
  }
 }
 if (atHour!=null) {
  time = time.withTime(atHour, atMinute!=null ? atMinute : 0, 0, 0);
 }
 return time;
}

代码示例来源:origin: plusonelabs/calendar-widget

/**
 * from http://stackoverflow.com/a/5451245/297710
 */
private void reproducedTimeZoneOffsetTransitionException() {
  final DateTimeZone dateTimeZone = DateTimeZone.forID("CET");
  LocalDateTime localDateTime = new LocalDateTime(dateTimeZone)
      .withYear(2011)
      .withMonthOfYear(3)
      .withDayOfMonth(27)
      .withHourOfDay(2);
  // this is just here to illustrate I'm solving the problem;
  // don't need in operational code
  try {
    DateTime myDateBroken = localDateTime.toDateTime(dateTimeZone);
    fail("No exception for " + localDateTime + " -> " + myDateBroken);
  } catch (IllegalArgumentException iae) {
    Log.v(TAG, "Sure enough, invalid instant due to time zone offset transition: "
        + localDateTime);
  }
  if (dateTimeZone.isLocalDateTimeGap(localDateTime)) {
    localDateTime = localDateTime.withHourOfDay(3);
  }
  DateTime myDate = localDateTime.toDateTime(dateTimeZone);
  Log.v(TAG, "No problem with this date: " + myDate);
}

代码示例来源:origin: org.motechproject/motech-platform-commons-date

public static DateTime newDateTime(LocalDate localDate, int hour, int minute, int second) {
  final DateTimeZone zone = DateTimeSourceUtil.timeZone();
  LocalDateTime localDateTime = new LocalDateTime(zone)
      .withYear(localDate.getYear())
      .withMonthOfYear(localDate.getMonthOfYear())
      .withDayOfMonth(localDate.getDayOfMonth())
      .withHourOfDay(hour)
      .withMinuteOfHour(minute)
      .withSecondOfMinute(second)
      .withMillisOfSecond(0);
  if (zone.isLocalDateTimeGap(localDateTime)) {
    localDateTime = localDateTime.withHourOfDay(hour + 1);
  }
  return localDateTime.toDateTime();
}

相关文章