看看
strtotime,
strptime或
DateTime课.
strtotime例子:
$timestamp = strtotime('1/1/2011');
每个功能都有其警告.例如,strtotime的文档规定:
Dates in the m/d/y or d-m-y formats
are disambiguated by looking at the
separator between the various
components: if the separator is a
slash (/), then the American m/d/y is
assumed; whereas if the separator is a
dash (-) or a dot (.), then the
European d-m-y format is assumed.
您还可以使用preg_match捕获所有3个部分,并使用mktime创建自己的时间戳.
preg_match示例:
if ( preg_match('/^(?P\d+)[-\/](?P\d+)[-\/](?P\d+)$/', '1/1/2011', $matches) )
{
$timestamp = mktime(0, 0, 0, ( $matches['month'] - 1 ), $matches['day'], $matches['year']);
}