PHP timestamp (UNIX) usage detailed

Source: Internet
Author: User
The timestamp is the number of seconds since January 1, 1970 (00:00:00 GMT). It is also known as the Unix timestamp (Unix Timestamp).

The Unix time stamp (Unix timestamp), or Unix time, or POSIX time, is a time representation defined as the total number of seconds from GMT January 01, 1970 00:00 00 seconds to now. Unix timestamps are used not only in UNIX systems, Unix-like systems, but also in many other operating systems. This article mainly introduces the PHP Unix timestamp usage, and analyzes the PHP Unix timestamp correlation function and the usage skill with the instance form. , specifically as follows:

The timestamp is the creation, modification, and access time in the file properties. Digital timestamp service is one of the Web site Security service items, which can provide the security protection of date and time information of electronic files.

The advantages of timestamps are:

The encrypted value can be changed to prevent the value from being stolen and reused illegally, which plays the role of encryption. Timestamps are mainly dependent on time and produce a unique value for a specified period of time.

Unix time stamp

In Unix systems, the date and time are expressed as the number of seconds from 0 o'clock January 1, 1970 to the current time, which is called the Unix timestamp, expressed as a 32-bit binary number. This time representation is supported in different operating systems and is represented in UNIX and windows at the same time, so there is no need to convert from one system to another.

The current UNIX timestamp is represented by a 32-bit binary number, the 32-bit binary value range is ( -2147483648~+2147483647), because the system does not support a negative timestamp, so the current UNIX timestamp can represent the maximum time is January 19, 2038 3:14 7 seconds, The timestamp of the moment is 2147483647. After that time, you need to extend the bits number of Unix timestamps.

PHP gets the timestamp of the specified date

PHP applies the mktime () function to convert a time into a Unix timestamp value.

The syntax is as follows

Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
parameter description
hour optional. Specified hours.
minute optional. Specify minutes.
second optional. Specify seconds.
month optional. Specifies the number of months to be represented.
day optional. Prescribed days.
year optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
is_dst

Optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1.

Since 5.1.0, the IS_DST parameter has been discarded. Therefore, you should use the new Time zone processing feature.

For example:

echo "Timestamp:". Mktime (). ' <br> ';//returns the current timestamp echo "Any date:". Date ("Y-m-d", Mktime (0,0,0,2,21,1996)). ' <br> '; Echo ' current date: '. Date ("Y-m-d", Mktime ()). ' <br> ';

The result of the operation is:

Timestamp: 1458979695 Any date: 1996-02-21 Current date: 2016-03-26

Gets the current time stamp

PHP obtains the current UNIX timestamp through the time () function.

The syntax is as follows:

int time(void);

The function has no parameters, and the return value is the integer value of the Unix timestamp.

For example:

Echo time (). " <br> ";//output current timestamp $nextweek = time () + (7*24*60*60);//One weeks seven days, 24 hours a day, 一个小时60分, one minute 60 seconds echo" Now: ". Date (" y-m-d ")." <br> "; echo" Next Week: ". Date (" y-m-d ", $nextWeek);

Run the result as

1458980073now:2016-03-26next week:2016-04-02
Related Article

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.