我想计算一个持续时间,而1天将包括8个小时。
创建新的年表是正确的方法吗?

我确实尝试创建了一个自定义年表,并用类似以下内容的方法覆盖了assemble方法:

int millisPerDay = 1000 * 60 * 60 * 8;

fields.days = new PreciseDurationField(DurationFieldType.days(), millisPerDay);


但是,它没有达到预期的效果。

有什么建议么?

先感谢您

最佳答案

为了回答我自己的问题,下面是一个完整的按时间顺序排列的课程(为时8小时)。
我将其发布在这里,以便对尝试解决类似问题的其他人有所帮助。


import org.joda.time.Chronology;
import org.joda.time.DateTimeZone;
import org.joda.time.DurationFieldType;
import org.joda.time.field.PreciseDurationField;
import org.joda.time.chrono.AssembledChronology;
import org.joda.time.chrono.GregorianChronology;

public final class EightHoursDayChronology extends AssembledChronology {

   private static final EightHoursDayChronology INSTANCE_UTC;

  static{
  INSTANCE_UTC = new EightHoursDayChronology(GregorianChronology.getInstanceUTC());
  }


  public static EightHoursDayChronology getInstance(){
       return INSTANCE_UTC  ;
  }

    private EightHoursDayChronology(Chronology base) {
        super(base, null);
    }

    @Override
   protected void assemble(org.joda.time.chrono.AssembledChronology.Fields fields) {

    int millisPerDay = 1000 * 60 * 60 * 8   ;
    fields.days = new PreciseDurationField(DurationFieldType.days(), millisPerDay)
  }

   @Override
  public Chronology withUTC() {
    return INSTANCE_UTC    ;
  }

    @Override
    public Chronology withZone(DateTimeZone zone) {
        throw new UnsupportedOperationException("Method was not implemented");
    }

    @Override
    public String toString() {
        return "EightHoursDayChronology";
    }

}

10-07 23:34