Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. We can use the php built-in function strtotime to format the date as the timestamp, however, because my input box does not use the date control, you need to enter the date by yourself. In order to be more friendly to user input, a very basic Time Stamp conversion method is provided, regardless of user input: 20131122085959, 08:59:59, 2013-11.22085959, and so on can be formatted normally.
/**
* Date string to Timestamp
* Author: HongPing [hongping626@qq.com] 2013.11.22
* @ Param string $ date time string
* @ Return unixtime
*/
Function toUnix ($ date ){
If (empty ($ date )){
Return '';
}
$ FArr = str_split ('20140901'); $ dArr = str_split ($ date );
$ Fmdate = '';
Foreach ($ dArr as $ v ){
If (in_array ($ v, $ fArr )){
$ Fmdate. = $ v;
}
}
$ Year = (int) substr ($ fmdate, 0, 4); // year
$ Month = (int) substr ($ fmdate, 4, 2); // month
$ Day = (int) substr ($ fmdate, 6, 2); // day
$ Hour = (int) substr ($ fmdate, 8, 2); // hour
$ Minu = (int) substr ($ fmdate, 10, 2); // minute
$ Send = (int) substr ($ fmdate, 12, 2); // second
$ Hour = $ hour? $ Hour: 0; $ minu = $ minu? $ Minu: 0; $ send = $ send? $ Send: 0; $ month = $ month? $ Month: 0; $ day = $ day? $ Day: 0; $ year = $ year? $ Year: 0;
Return mktime ($ hour, $ minu, $ send, $ month, $ day, $ year );
// Return strtotime ($ date );
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB