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