PHP Custom Time conversion Function Example _php tips

Source: Internet
Author: User
Tags php programming php regular expression

This example describes the PHP custom time conversion function. Share to everyone for your reference, specific as follows:

We can encapsulate functions that are often used in abstract classes and then inherit to use them.

/** * Time stamp * @param object $STR * @return Timestamp/function ToTime ($str, $flag = FA
    LSE) {$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 time * @param object $STR * @return/function toDate ($str, $flag = False) {if ($flag) {$dat E_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 a variety of common language for time stamping operation methods, provided to you for reference:

Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime

More about PHP Interested readers can view the site topics: "PHP date and Time usage summary", "PHP Mathematical Calculation Skills Summary", "PHP Array" operation Skills Encyclopedia, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Regular Expression Usage summary, "Summary of PHP operations and operator usage", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.