In public account development, the time parameters in almost all interfaces that interact with the server are of the integer type. to display the time correctly, the time must be converted. In public account development, the time parameters in almost all interfaces that interact with the server are of the integer type. to display the time correctly, the time must be converted.
Description of time integer:
At first, the computer operating system was 32 bits, and the time was expressed as 32 bits. The maximum value of 32 bits is 2147483647. In addition, the total number of seconds for the first day of the year is 31536000,2147483647/365 = 31536000, that is to say, the maximum time for 32 bits to represent is 68 years. In fact, by the time of on January 1, 68.1, the maximum time is reached. after this time point, the time of all 32-bit operating systems will change to 10000000 00000000 00000000 00000000, that is, December 13, 1901, 45 minutes, and 52 seconds, in this way, there will be time regression, and many software will run abnormally. Here, I think the answer to the question has come out: because the maximum interval of time expressed by 32 bits is 68 years, the earliest UNIX operating system took into account the generation of computers and the TIME limit of applications, and took January 1, 1970 as the epoch TIME (start TIME) of unix time ), as for the phenomenon of time regression, we believe that 64-bit operating systems will be gradually solved with the emergence of 64-bit operating systems, because the 64-bit operating system can represent 292,277,026,596-, seconds, I believe that even if the Earth is destroyed, we don't have to worry about it enough, because this time is already years later.
That is to say, the time integer is actually the number of seconds since January 1, January 1, 1970. it's easy to figure out the principle.
The conversion code is as follows:
Public static String paserTime (int time) {System. setProperty ("user. timezone "," Asia/Shanghai "); TimeZone tz = TimeZone. getTimeZone ("Asia/Shanghai"); TimeZone. setDefault (tz); SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); String times = format. format (new Date (time * 1000L); System. out. print ("date format ---->" + times); return times ;}
The above is the detailed introduction of how to implement time conversion code instances in development. For more information, see other related articles on php Chinese network!