Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jodatime天数周期类型问题/错误_Java_Time_Jodatime - Fatal编程技术网

Java jodatime天数周期类型问题/错误

Java jodatime天数周期类型问题/错误,java,time,jodatime,Java,Time,Jodatime,我对JodaTimeAPI有问题。我不明白为什么这个测试不起作用。我需要确定X毫秒内有多少天、小时、分和秒。但是天数值没有解析。。。。有什么想法吗 @Test public void testTime() { long secs = 3866 * 24 * 35; long msecs = secs * 1000; //Period period = duration.toPeriod(); PeriodType periodType = PeriodType

我对JodaTimeAPI有问题。我不明白为什么这个测试不起作用。我需要确定X毫秒内有多少天、小时、分和秒。但是天数值没有解析。。。。有什么想法吗

@Test
public void testTime() {
    long secs = 3866 * 24 * 35;
    long msecs = secs * 1000;
    //Period period = duration.toPeriod();


    PeriodType periodType = PeriodType.forFields(
            new DurationFieldType[]{
                    DurationFieldType.days(),
                    DurationFieldType.hours(),
                    DurationFieldType.minutes(),
                    DurationFieldType.seconds(),
            });
    Duration duration = Duration.standardSeconds(secs);
    Period period = duration.toPeriod(periodType, GregorianChronology.getInstance());

    System.out.println("days:" + period.getDays());
    System.out.println("hours:" + period.getHours());
    System.out.println("mins:" + period.getMinutes());
    System.out.println("seconds:" + period.getSeconds());
    PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
            .printZeroAlways()
            .minimumPrintedDigits(2)
            .appendDays()
            .appendSeparator(":")
            .appendHours()
            .appendSeparator(":")
            .appendMinutes()
            .appendSeparator(":")
            .appendSecondsWithOptionalMillis()
            .toFormatter();
    StringBuffer stringBuffer = new StringBuffer();
    periodFormatter.printTo(stringBuffer, period);
    System.out.println(">>>" + stringBuffer);
}
输出是 天数:0 小时:902 分钟:4 秒:0
0:902:04:04:

< P>你所使用的年表可能不考虑准确的日子。不要使用GregorianChrology,请尝试使用
IOSChronology.getInstanceUTC()

您需要使用以下方法规范化周期:

Period normalizedPeriod = period.normalizeStandard();

然后,您可以使用normalizedPeriod并查看您要查找的结果。 作为一个快速测试,我修改了您的junit测试用例并添加了以下行:

period = period.normalizedStandard();
就在您完成后,从持续时间中创建时段。

这是的副本
period = period.normalizedStandard();