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

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

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

LocalTime.plusMillis介绍

[英]Returns a copy of this time plus the specified number of millis.

This LocalTime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

LocalTime added = dt.plusMillis(6); 
LocalTime added = dt.plus(Period.millis(6)); 
LocalTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);

[中]返回此时间加上指定毫秒数的副本。
此LocalTime实例是不可变的,不受此方法调用的影响。
以下三行实际上是相同的:

LocalTime added = dt.plusMillis(6); 
LocalTime added = dt.plus(Period.millis(6)); 
LocalTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);

代码示例

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

long movingAverage = 0;
 // 1. define offset
 LocalTime offset = new LocalTime("12:00:00");
 long offsetMillis = offset.getMillisOfDay();
 for (String date : times) {
   long sampleMillis = new LocalTime(date).getMillisOfDay();
   // align to offset
   if (sampleMillis < offsetMillis)
     sampleMillis += DateTimeConstants.MILLIS_PER_DAY;
   long diff = sampleMillis - offsetMillis;
   // 2. use moving average
   movingAverage = movingAverage + diff / times.size();
 }
 // 3. avoid LocalTime(long) constructor
 LocalTime result = offset.plusMillis((int) movingAverage);
 System.out.println(result); // 23:48:54.329

代码示例来源:origin: com.synaptix/SynaptixWidget

@Override
  protected void buildNodeNames() {
    this.nodeNames.clear();
    if (nodes != null && !nodes.isEmpty()) {
      for (int i = 0; i < nodes.size(); i++) {
        TimeNode node = nodes.get(i);

        StringBuilder sb = new StringBuilder(node.getName());
        sb.append("\n");

        boolean arrive = i > 0;
        boolean depart = i < nodes.size() - 1;
        boolean passage = node.getPause() == null || node.getPause().getMillis() == 0;
        if (arrive || passage) {
          sb.append(node.getTime().toString(StaticWidgetHelper.getSynaptixDateConstantsBundle().displayTimeFormat()));
        }
        if (arrive && depart && !passage) {
          sb.append(" - ");
        }
        if (depart && !passage) {
          sb.append(node.getTime().plusMillis((int) node.getPause().getMillis()).toString(StaticWidgetHelper.getSynaptixDateConstantsBundle().displayTimeFormat()));
        }
        nodeNames.add(sb.toString());
      }
    }
  }
}

相关文章