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

x33g5p2x  于2022-01-17 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(156)

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

DateTime.withFieldAdded介绍

[英]Returns a copy of this datetime with the value of the specified field increased.

If the addition is zero or the field is null, then this is returned.

These three lines are equivalent:

DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); 
DateTime added = dt.plusYears(6); 
DateTime added = dt.plus(Period.years(6));

[中]返回此datetime的副本,指定字段的值增加。
如果加法为零或字段为空,则返回this
这三条线是等效的:

DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); 
DateTime added = dt.plusYears(6); 
DateTime added = dt.plus(Period.years(6));

代码示例

代码示例来源:origin: apache/incubator-gobblin

@Override
public long getWatermarkIncrementMs() {
 return new DateTime(0).withFieldAdded(this.incrementalUnit, 1).getMillis();
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public List<FileInfo> getFilesToProcess(long minWatermark, int maxFilesToReturn)
  throws IOException {
 DateTime currentDay = new DateTime().minus(leadTimeDuration);
 DateTime lowWaterMarkDate = new DateTime(minWatermark);
 List<FileInfo> filesToProcess = new ArrayList<>();
 try {
  helper.connect();
  this.fs = helper.getFileSystem();
 } catch (FileBasedHelperException e) {
  throw new IOException("Error initializing FileSystem", e);
 }
 for (DateTime date = lowWaterMarkDate; !date.isAfter(currentDay) && filesToProcess.size() < maxFilesToReturn;
   date = date.withFieldAdded(incrementalUnit, 1)) {
  // Constructs the path folder - e.g. /my/data/prefix/2015/01/01/suffix
  Path sourcePath = constructSourcePath(date);
  if (this.fs.exists(sourcePath)) {
   for (FileStatus fileStatus : getFilteredFileStatuses(sourcePath, getFileFilter())) {
    LOG.info("Will process file " + fileStatus.getPath());
    filesToProcess.add(new FileInfo(fileStatus.getPath().toString(), fileStatus.getLen(), date.getMillis()));
   }
  }
 }
 return filesToProcess;
}

代码示例来源:origin: klout/brickhouse

DateTime endDt = dateFormatter.parseDateTime(end);
int i = 0;
for (DateTime dt = startDt; dt.isBefore(endDt) || dt.isEqual(endDt); dt = dt.withFieldAdded(
    durationType, incr), i++) {
  this.forwardListObj[0] = dateFormatter.print(dt);

代码示例来源:origin: facebook/jcommon

/**
 * Gets the start instant given the event instant, interval length
 * and the time zone for this interval type.
 *
 * @param instant the event time instant.
 * @param length the interval length
 *
 * @return the start instant of the interval of given length that contains
 * the supplied time instant in the supplied time zone
 */
public DateTime getTimeIntervalStart(DateTime instant, long length) {
 validateValue(instant.getZone(), length);
 // Reset all the fields
 DateTime periodStart = instant.property(truncateFieldType)
  .roundFloorCopy();
 // figure out the which time interval does the instant lie in
 Period period = new Period(periodStart, instant, periodType);
 DurationField durationField = fieldType.getField(instant.getChronology()).getDurationField();
 int diff = period.get(durationField.getType());
 long startDelta = (diff / length) * length;
 return periodStart.withFieldAdded(durationField.getType(), FieldUtils.safeToInt(startDelta));
}

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

public static DateTime rollForwardWith(ReadableInstant now, AbstractPartial lp) {
  DateTime dt = lp.toDateTime(now);
  while (dt.isBefore(now)) {
    dt = dt.withFieldAdded(lp.getFieldTypes()[0].getRangeDurationType(), 1);
  }
  return dt;
}

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

public static void main(String[] args) {

 DateTime dateTime = FORMATTER.parseDateTime("24/10/2009");
 Instant pInstant = dateTime.withFieldAdded(DurationFieldType.days(),2).toInstant();
 System.out.println("24/10/2009  + 2 Days = " + pInstant.toString(FORMATTER));
}

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

@Override
public long getWatermarkIncrementMs() {
 return new DateTime(0).withFieldAdded(this.incrementalUnit, 1).getMillis();
}

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

@Override
public List<FileInfo> getFilesToProcess(long minWatermark, int maxFilesToReturn)
  throws IOException {
 DateTime currentDay = new DateTime().minus(leadTimeDuration);
 DateTime lowWaterMarkDate = new DateTime(minWatermark);
 List<FileInfo> filesToProcess = new ArrayList<>();
 try {
  helper.connect();
  this.fs = helper.getFileSystem();
 } catch (FileBasedHelperException e) {
  throw new IOException("Error initializing FileSystem", e);
 }
 for (DateTime date = lowWaterMarkDate; !date.isAfter(currentDay) && filesToProcess.size() < maxFilesToReturn;
   date = date.withFieldAdded(incrementalUnit, 1)) {
  // Constructs the path folder - e.g. /my/data/prefix/2015/01/01/suffix
  Path sourcePath = constructSourcePath(date);
  if (this.fs.exists(sourcePath)) {
   for (FileStatus fileStatus : getFilteredFileStatuses(sourcePath, getFileFilter())) {
    LOG.info("Will process file " + fileStatus.getPath());
    filesToProcess.add(new FileInfo(fileStatus.getPath().toString(), fileStatus.getLen(), date.getMillis()));
   }
  }
 }
 return filesToProcess;
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public Interval getInterval() {
  final DateTime beginningOfSemester = new DateTime(getAttends().getBegginingOfLessonPeriod());
  final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
  final DateTime start = firstMonday.withFieldAdded(DurationFieldType.weeks(), getWeekOffset().intValue());
  final DateTime end = start.plusWeeks(1);
  return new Interval(start, end);
}

代码示例来源:origin: perfectsense/dari

protected DateTime every(DateTime currentTime, DateTimeFieldType unit, int offset, int interval) {
  DateTime d = currentTime.property(unit).roundFloorCopy();
  d = d.withFieldAdded(unit.getDurationType(), offset);
  return d.withField(unit, (d.get(unit) / interval) * interval);
}

代码示例来源:origin: orgzly/org-java

curr = time.withFieldAdded(OrgDateTimeUtils.getDurationFieldType(repeater.getUnit()), addUnits);
curr = curr.withFieldAdded(
    OrgDateTimeUtils.getDurationFieldType(repeater.getUnit()),
    repeater.getValue()

代码示例来源:origin: sismics/reader

Date dateMin = new DateTime().withFieldAdded(DurationFieldType.days(), -1).toDate();
for (ArticleDto newerLocalArticle : newerLocalArticles) {
  if (!newerArticleGuids.contains(newerLocalArticle.getGuid()) && newerLocalArticle.getCreateDate().after(dateMin)) {

相关文章

DateTime类方法