我想计算一段时间,而1天则需要8小时。 创建新的年表是正确的方法吗?
我确实尝试创建一个自定义的年代表,并用以下内容覆盖汇编方法:
int millisPerDay = 1000 * 60 * 60 * 8;
fields.days = new PreciseDurationField(DurationFieldType.days(), millisPerDay);
然而,它没有达到预期的效果。
有什么建议吗?
提前谢谢
答案 0 :(得分:6)
要回答我自己的问题,以下是一个完整的工作年表(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";
}
}