WeChat public account development tutorial 10th-CreateTime_PHP tutorial on message creation time in resolution interface

Source: Internet
Author: User
Public Account Development Tutorial Article 10th-the creation time of the message in the resolution interface is CreateTime. The message Interface Guide of the public platform shows that each type of message definition contains the CreateTime parameter, which indicates the creation time of the message, as shown in: the message Interface Guide of the public platform shows that each type of message definition contains the CreateTime parameter, which indicates the creation time of the message, as shown in:

Is the definition of the 4.1-text message in the Message Interface Guide. Note the CreateTime description: the message creation time (integer), which focuses on the time of an integer, rather than the familiar time similar to "yyyy-MM-dd HH: mm: standard format time of ss. This article mainly introduces the meaning of CreateTime, the creation time of an integer Message defined in the message interface, and how to convert CreateTime to a familiar time format.

Meaning of integer CreateTime

The creation time of a message defined in the message interface, CreateTime, indicates the number of seconds between 00:00:00, January 1, January 1, 1970 and the creation time of the message. Note that the number of seconds is not the number of milliseconds!

Integer CreateTime conversion

In Java, we often use the following two methods to obtain the long type of time:

/*** Demonstrate two common methods for obtaining long time in Java */public static void main (String [] args) {long longTime1 = System. currentTimeMillis (); // 13732061431_system. out. println (longTime1); long longTime2 = new java. util. date (). getTime (); // 1373206143381System. out. println (longTime2 );}

The above two methods for obtaining long time are equivalent. The obtained results indicate the number of milliseconds between the time and the time 00:00:00 on January 1, January 1, 1970. Note that this is the number of milliseconds! How can we convert the time of the long type obtained here to the time of the standard format? The method is as follows:

/*** Demonstrate two common methods for obtaining long time in Java */public static void main (String [] args) {// current time (milliseconds from 00:00:00, January 1,) long longTime = 137320614310000l; String stdFormatTime = formatTime (longTime); // output: January 1, 1970 22: 09: 03System. out. println (stdFormatTime);}/*** converts a long time to a standard format (yyyy-MM-dd HH: mm: ss) ** @ param longTime * @ return */public static String formatTime (long longTime) {DateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss "); return format. format (new Date (longTime ));}

The preceding example shows how to convert a long type of time to a standard format, but simply uses the SimpleDateFormat class for better understanding. Then, let's go back to today's topic and how to convert CreateTime to a standard format.

In the message interface, CreateTime indicates the number of seconds from January 1, 1970, while System. currentTimeMillis () indicates the number of milliseconds from January 1, 1970. the conversion between them is equivalent to: 1 Second = 1000 milliseconds. if CreateTime is multiplied by 1000, it becomes the number of milliseconds from January 1, 1970, the preceding formatTime () method can be used for processing. isn't it easy?

Next, I will encapsulate another method to convert the creation time of an integer message in the message, CreateTime, to the standard format, as shown below:

/*** Convert the CreateTime in the message to the standard format (yyyy-MM-dd HH: mm: ss) ** @ param createTime the creation time of the message * @ return */public static String formatTime (String createTime) {// convert the input CreateTime to the long type, multiply by 1000 long msgCreateTime = Long. parseLong (createTime) * 1000L; DateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); return format. format (new Date (msgCreateTime ));}

:...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.