Php custom time Conversion Function example, php custom function example

Source: Internet
Author: User

Php custom time Conversion Function example, php custom function example

This article describes the php custom time conversion function. We will share this with you for your reference. The details are as follows:

We can encapsulate frequently used functions in abstract classes and use them by inheritance.

/*** Time to timestamp * @ param object $ str * @ return timestamp */function toTime ($ str, $ flag = false) {$ year = substr ($ str, 0, 4); $ month = substr ($ str, 5, 2); $ day = substr ($ str, 8, 2); $ hour = substr ($ str, 11,-3); $ min = substr ($ str,-2); if ($ flag) {$ intTime = strtotime ($ year. '-'. $ month. '-'. $ day. ''. $ hour. ':'. $ min);} else {$ intTime = strtotime ($ year. '-'. $ month. '-'. $ day) ;}// echo $ intTime; exit; return $ intTime; // int}/*** timestamp transfer time * @ param object $ str * @ return */function toDate ($ str, $ flag = false) {if ($ flag) {$ date_str = date ('y', $ str ). '-'. date ('M', $ str ). '-'. date ('D', $ str ). ''. date ('h', $ str ). ':'. date ('I', $ str);} else {$ date_str = date ('y', $ str ). '-'. date ('M', $ str ). '-'. date ('D', $ str);} return $ date_str ;}

PS: This site also provides a Unix timestamp conversion tool, including the timestamp operation methods in various common languages, for your reference:

Unix timestamp Conversion Tool:
Http://tools.jb51.net/code/unixtime

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.