Timestamp and date conversion

Source: Internet
Author: User
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... UNIX_TIMESTAMP (), UNIX_TIMESTAMP (date)
If no parameter is called, a Unix timestamp ('2017-01-01 00:00:00 'seconds after GMT) is returned as an unsigned integer. If you use date to call UNIX_TIMESTAMP (), it will return the parameter value in the form of the number of seconds after '2017-01-01 00:00:00 'GMT. Date can be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the YYMMDD or YYYMMDD format of the local time.

mysql> SELECT UNIX_TIMESTAMP();    -> 882226357    mysql> SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');    -> 875996580

When UNIX_TIMESTAMP is used in the TIMESTAMP column, the function returns an internal timestamp value without any implicit conversion of "string-to-Unix-TIMESTAMP. If you pass an overflow date to UNIX_TIMESTAMP (), it returns 0, but note that only the basic range check will be executed (year from 1970 to 2037, month from 01 to 12, from 01 to 31 ).
Example of mutual conversion between timestamp and time in PHP:
PHP code

$ Timestamp = 1210003200; $ datetime = date ('Y-m-d H: I: S', $ timestamp); echo "the time stamp represents :", $ datetime ,"
\ N "; echo" returns the timestamp from this time: ", strtotime ($ datetime ),"
\ N ";

Example of timestamp conversion in MySQL:

SQL code

select from_unixtime(1210003200) datetime, unix_timestamp(from_unixtime(1210003200)) 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.