An example of how to perform time conversion code in WeChat development

伊谢尔伦
Release: 2017-04-29 15:57:42
Original
2971 people have browsed it

In the development of WeChat public accounts, the time parameters in almost all interfaces that interact with the WeChat server are of integer type, and must be converted to display the time correctly.

Description of time integer type:

Initially the computer operating system was 32-bit, and time was also expressed in 32-bit. The maximum value that can be represented by 32 bits is 2147483647. In addition, the total number of seconds in 1 year and 365 days is 31536000, 2147483647/31536000 = 68.1, which means that the longest time that 32 bits can represent is 68 years, but in fact it will be 03:14:07 on January 19, 2038. The maximum time will be reached. After this time point, the time of all 32-bit operating systems will become 10000000 00000000 00000000 00000000, which is 20:45:52 on December 13, 1901. This will cause time regression. , many software will run abnormally. At this point, I think the answer to the question has come out: because the maximum interval of time expressed in 32 bits is 68 years, and the earliest UNIX operating system took January 1970 into account, taking into account the age of the computer and the time limit of its application. The 1st is the epoch time (start time) of UNIX TIME. As for the phenomenon of time regression, I believe it will be gradually solved with the emergence of 64-bit operating systems, because using 64-bit operating systems can represent 15:30 on December 4, 292,277,026,596 08 seconds, I believe that our N-generation descendants will not have to worry about not having enough even if the earth is destroyed, because this time is already hundreds of billions of years later.

That is to say: the time integer is actually the number of seconds since January 1, 1970. Now that the principle is clear, it is simple.

The conversion code is shown below:

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("日期格式---->" + times);  
      return times;  
}
Copy after login

The above is the detailed content of An example of how to perform time conversion code in WeChat development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template