0

In java Calendar class while adding milliseconds I am missing the decimal precession. Since method expects integer

For example: 1000/12 = 83.333333

In java
Calendar c = Calendar.getInstance(); c.add(Calendar.MILLISECOND, (integer));

Which takes only 83 and .33333 is missed.

Does anybody know how to handle this scenario in java ?

vishwas
  • 35
  • 9

1 Answers1

2

java.util.Calendar keeps time information at the level of milliseconds,

An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).

java.time.LocalDateTime has a sensitivity in the level of nanosecond.

Time is represented to nanosecond precision. For example, the value "2nd October 2007 at 13:45.30.123456789" can be stored in a LocalDateTime.

so if you need microsecond or nanosecond level information, you can not use java.util.Calendar, and you should use java.time.LocalDateTime.

guleryuz
  • 2,714
  • 1
  • 15
  • 19
  • For actual moments use `Instant`, `OffsetDateTime`, and `ZonedDateTime`. The `LocalDateTime` class lacks any concept of time zone or offset-from-UTC and so does *not* represent specific point on the timeline. – Basil Bourque Mar 09 '18 at 21:24