你好,这对我来说很好,但我认为可以更简单的任何人帮助我使用此代码检查用户输入的时间和日期
function ckeck_date($sug_date, $sug_time)
{
if ($sug_date[0] == NULL)
{
return TRUE;
}
else
{
for ($i = 0; $i < count($sug_date); $i++)
{
if ($this->_totimestamp($sug_date[$i], $sug_time[$i]) < mktime(23, 59, 59, date('m'), date('d') - 1, date('Y')))
{
$x=false;
}
else $y=true;
}
}
if(isset($x))
{
return $x*$y;
}
else return true;
}
答案 0 :(得分:2)
试试这个,记下你的日期和时间
$str = '2012-06-15 11:12:23'; // OR '15-06-2012 11:12:23'
if ( strtotime( $str ) > time( ) ) {
// Your time is greater than current time
}
答案 1 :(得分:0)
您可以使用以下日期:
使用strtotime,您可以从字符串创建int
并在将来比较它们(如果您与now
进行比较)
$today = strtotime(date("Y-m-d")); // today's date
$userd = strtotime("2012-10-16"); // users input
if ($userd > $today){
$valid = "yes";
} else {
$valid = "no";
}
如果我是对的,您也可以将时间添加到输入中,但是您需要检查关于此的php文档以获取正确的日期时间格式
更短的:
if (strtotime($userdate) > strtotime(date("Y-m-d"))){
$valid = "yes";
}