Java – why does jodatime and calendar return different results

Why did this test fail:

DateTime dateTime = new DateTime(1997,01,00,DateTimeZone.UTC);
    long jodaMills = dateTime.getMillis();

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.set(1997,00);
    long calMills = cal.getTimeInMillis();

    Assert.assertEquals(jodaMills,calMills);

I got the following results: estimated: 852076800000 actual: 854755200964

Shouldn't they be the same number?

Solution

Two reasons:

>Joda has a month So you need to change. > The calendar is poorly designed. You did not set the milliseconds of seconds to 0 cal. set(MILLISECOND,0)

This is Javadoc

Which is the millisecond field

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>