PHP date/time to timestamp (custom format)
Any one got a function to like strtotime() 开发者_Go百科but the takes the format as input?
For example I need to convert yyyymmdd to a timestamp, or perhaps yyyyddmm. So I would like to specify the format used. Also Im on Windows so strptime() isn't an option.
PHP 5's DateTime class has the createFromFormat method which does what you need.
However, it requires PHP 5.3 so it's not always an option (yet).
Very easy to write a function, just take a look at mktime...
// Assumes yyyy-mm-dd
function fromdate($date) {
$d = explode("-", $date);
return mktime(0, 0, 0, $d[1], $d[2], $d[0]);
}
加载中,请稍侯......
精彩评论