Calendar.clear (int Field) trap

zhaozj2021-02-16  43

Run the following code, what do you expect to output?

/ / Hypothesis now is 11:34:03 Calendar Cal = Calendar.GetInstance (); caledar.Hour_of_day, 5); Cal.clear (Calendar.Hour_Of_Day); Cal.clear (Calendar.Calendar.second ); System.out.println ("h:" Cal.get (Calendar.Hour_Of_Day) ", S:" Cal.Get (Calendar.Second);

You must think of h: 0, s: 0

What? Isn't it? Where is H: 5, S: 3

neither!!!

Output H: 11, S: 0

Oh, is it incredible?

The original Calender's Clear (int) method is not clear,

For Hour, Hour_Of_DAY is returning the most original value.

Other may be clear.

In short, it is not an insurance method, or it is still replaced with a method such as Set (Hour, 0).

转载请注明原文地址:https://www.9cbs.com/read-21424.html

New Post(0)