16/7/11_php-getting the current UNIX timestamp

Source: Internet
Author: User
Tags echo date time and date

Gets the current UNIX timestamp

The UNIX timestamp (called: timestamp) is a very important concept in PHP for time and date, which represents the sum of the seconds from January 1, 1970 00:00:00 to the current time.

PHP provides a built-in function time () to get the timestamp of the current time of the server. It is easy to get the current UNIX timestamp.

$time = time (); Echo $time;//1396193923, this number represents 1,396,193,923 seconds from January 1, 1970 00:00:00 When I output this script.
Get the current date

PHP has a date () function built into it to get the current day.

Function Description: Date (timestamp format, specified timestamp "default is the current date and time, optional")

Return value: function date and time

Example:

The date function, the second parameter takes the default value in the case of Echo date ("y-m-d"), the//2014-03-30//date function, the second argument has the value of the case of the Echo date ("y-m-d", ' 1396193923 ');// 2014-03-30,1396193923 represents the Unix timestamp for 2014-03-30
Unix timestamp of date acquired

The UNIX timestamp (called: timestamp) is a very important concept in PHP for time and date, which represents the sum of the seconds from January 1, 1970 00:00:00 to the current time.

PHP provides built-in function Strtotime implementations: Gets the timestamp of a date, or gets the timestamp of a time. For example:

echo strtotime (' 2014-04-29 ');//1398700800, this figure represents 1,398,700,800 seconds from January 1, 1970 00:00:00 to April 29, 2014. Echo strtotime (' 2014-04-29 00:00:01 ');//1398700801, this number means it's been 1,398,700,801 seconds since January 1, 1970 00:00:00 to 2014-04-29 00:00:01. Have you found the pattern? In fact strtotime (' 2014-04-29 ') is equivalent to Strtotime (' 2014-04-29 00:00:00 ')
Converts a formatted date string to a Unix timestamp

The Strtotime function expects to accept a string containing the U.S. English date format and attempt to resolve it to a Unix timestamp.

Function Description: Strtotime (time string to parse, calculates the timestamp of the return value "default is the current time, optional")
Return value: Success returns timestamp, otherwise FALSE

Like what

Echo Strtotime ("Now"), or//is equivalent to the current date and time of the English word, and converts the date time to a Unix timestamp. This effect is the same as echo time (). Echo strtotime ("+1 seconds") is equivalent to adding the current date and time to 1 seconds and converting the date time to a Unix timestamp. This effect is the same as echo time () +1. Echo strtotime ("+1 Day"), or the equivalent of adding the current date and time to 1 days. Echo strtotime ("+1 Week");//equivalent to the current date and time is added 1 weeks. Echo strtotime ("+1 Week 3 days 7 hours 5 Seconds"), or//equivalent to the current date and time is added 1 Weeks 3 day 7 hours 5 seconds.
Format Greenwich (GMT) Standard Time

The Gmdate function can format a GMT date and time, returning Greenwich Mean Time (GMT).

For example, we are now in the China time Zone is East eight, leading GMT 8 hours, sometimes called gmt+8, then the server run the following script to return the time should be this: the current time is assumed to be 2014-05-01 15:15:22echo date (' y-m-d H: I:s ', Time ()); The output is: 2014-05-01 15:15:22 echo gmdate (' y-m-d h:i:s ', Time ()); The output is: 2014-05-01 07:15:22 because GMT is now in China time zone minus 8 hours, so compared to the present time is less than 8 hours

16/7/11_php-getting the current UNIX timestamp

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.