Daily into the pit 1-Calendar class

1. One of the current time is the time, by the day of the date of calculation, need to pay attention

= Calendar.getInstance Calendar Calendar (); 
calendar.set (2019,10,1);
calendar.set (Calendar.DAY_OF_MONTH, -1);
time of day and date 2019.11.1 calculated on how much time the result to 2019.10.30, so you wonder? Why, God obviously was 31 October, the day should be 20.19.10.31 2019.11.1 fishes, two kinds of solutions:
(1) by the hour push forward
that is
= Calendar.getInstance Calendar Calendar (); 
calendar.set (2019,10,1);
calendar.set (Calendar. HOUR_OF_DAY, -24); // here by the hour to avoid the projected period last month was 31 days, but error 30 days according to the calculated error, the better the method solving 2

(2) GMT Time: i.e. GMT (Greenwich Mean Time). Mean solar time corresponds to the view of the sun, due to the Earth orbit non-circular, with the running speed changes from the earth and the sun changes, so depending upon the lack of uniformity in the sun. In order to correct this unevenness, astronomers calculate a non-circular trajectory earth polar axis of oblique viewing effect when the sun, while the sun is the flat after the apparent solar refers revised. When called flat world in the sun on the Greenwich meridian (UTC), also known as Greenwich Mean Time (GMT). So set up in China belong to the East eight districts, the district can be setup.

 
 
= Calendar.getInstance Calendar Calendar (); 
calendar.setTimeZone (TimeZone.getTimeZone ( "GMT")); // important
calendar.set (2019,10,1);
calendar.set (Calendar. The HOUR_OF_DAY , - 24) ; / / calendar.set (Calendar.DAY_OF_MONTH, -1); both of which are feasible

Guess you like

Origin www.cnblogs.com/911sky/p/12105298.html